Skip to content

feat(amqp): connection timeout#138

Merged
adam-hotait merged 1 commit intomainfrom
fix/connection-timeout
Mar 19, 2026
Merged

feat(amqp): connection timeout#138
adam-hotait merged 1 commit intomainfrom
fix/connection-timeout

Conversation

@adam-hotait
Copy link
Copy Markdown
Contributor

Add connection timeout for establishing a new connection

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable timeout for establishing new AMQP connections (socket connect + AMQP handshake) in @effect-messaging/amqp, defaulting to 10 seconds, and extends the test suite to cover the new option.

Changes:

  • Introduces connectionTimeout in AMQPConnectionOptions (default 10s) and wires it into connection establishment.
  • Applies both amqplib socket timeout and an Effect-level timeout around amqplib.connect(...).
  • Adds new test cases intended to cover default/custom timeout behavior and failure modes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
packages/amqp/src/internal/AMQPConnection.ts Implements connectionTimeout and applies it during connection initiation.
packages/amqp/src/AMQPConnection.ts Exposes the new option in the public AMQPConnectionOptions API docs.
packages/amqp/test/AMQPConnection.test.ts Adds tests for default/custom timeout configuration and timeout/failure behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +99 to +103
if (error._tag === "Fail") {
expect(error.error).toBeInstanceOf(AMQPError.AMQPConnectionError)
}
}
}).pipe(Effect.scoped))
Comment on lines +85 to +89
const { connectionRef, connectionTimeout, url } = yield* InternalAMQPConnection
yield* Effect.annotateCurrentSpan({ url })
yield* SubscriptionRef.updateEffect(connectionRef, () =>
Effect.gen(function*() {
const normalizedUrl = Redacted.isRedacted(url) ? Redacted.value(url) : url
Comment on lines +94 to +97
}).pipe(
Effect.timeout(connectionTimeout),
Effect.catchTag("TimeoutException", () => new AMQPConnectionError({ reason: "Connection timed out" }))
)
Comment on lines +95 to +97
Effect.timeout(connectionTimeout),
Effect.catchTag("TimeoutException", () => new AMQPConnectionError({ reason: "Connection timed out" }))
)
Comment on lines +79 to +80
*
* @since 0.7.0
Comment on lines +79 to +83
)
).toBe(true)
}
}
}).pipe(Effect.scoped))
Comment thread packages/amqp/test/AMQPConnection.test.ts Outdated
Comment thread packages/amqp/test/AMQPConnection.test.ts Outdated
Comment thread packages/amqp/src/internal/AMQPConnection.ts Outdated
{
private static defaultRetryConnectionSchedule = Schedule.forever.pipe(Schedule.addDelay(() => 1000))
private static defaultWaitConnectionTimeout = Duration.seconds(5)
private static defaultConnectionTimeout = Duration.seconds(10)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a good idea to keep this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good default. However, maybe we don't want to break consumers of the app? WDYT?

Comment thread packages/amqp/src/internal/AMQPConnection.ts Outdated
Comment thread packages/amqp/src/internal/AMQPConnection.ts Outdated
Comment thread packages/amqp/test/AMQPConnection.test.ts Outdated
Comment thread packages/amqp/test/AMQPConnection.test.ts Outdated
@adam-hotait adam-hotait force-pushed the fix/connection-timeout branch 3 times, most recently from 1350a45 to e9a542a Compare March 18, 2026 19:20
@adam-hotait adam-hotait force-pushed the fix/connection-timeout branch from e9a542a to 444e50f Compare March 19, 2026 08:49
@adam-hotait adam-hotait added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit 6c3e80a Mar 19, 2026
5 checks passed
@adam-hotait adam-hotait deleted the fix/connection-timeout branch March 19, 2026 09:41
@github-actions github-actions Bot mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants