-
Notifications
You must be signed in to change notification settings - Fork 202
feat: add SSE reconnection with retry support #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dab81a1
cf3dad4
6aafb56
cee5c9c
bd9a0f9
4491632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,3 @@ server: | |
|
|
||
| client: | ||
| - elicitation-sep1034-client-defaults | ||
| - sse-retry | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package io.modelcontextprotocol.kotlin.sdk.client | ||
|
|
||
| import kotlin.time.Duration | ||
| import kotlin.time.Duration.Companion.seconds | ||
|
|
||
| /** | ||
| * Options for controlling SSE reconnection behavior. | ||
| * | ||
| * @property initialReconnectionDelay The initial delay before the first reconnection attempt. | ||
| * @property maxReconnectionDelay The maximum delay between reconnection attempts. | ||
| * @property reconnectionDelayMultiplier The factor by which the delay grows on each attempt. | ||
| * @property maxRetries The maximum number of reconnection attempts per disconnect. | ||
| */ | ||
| public class ReconnectionOptions( | ||
| public val initialReconnectionDelay: Duration = 1.seconds, | ||
| public val maxReconnectionDelay: Duration = 30.seconds, | ||
| public val reconnectionDelayMultiplier: Double = 1.5, | ||
| public val maxRetries: Int = 2, | ||
| ) { | ||
| override fun equals(other: Any?): Boolean { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't use data class for this? to avoid manual hashCode/equals, and also it gives you the pattern options.copy([only specific fields])
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Data classes are indeed more convenient the problem is that any changes to them can introduce binary incompatibility in the future |
||
| if (this === other) return true | ||
| if (other == null || this::class != other::class) return false | ||
|
|
||
| other as ReconnectionOptions | ||
|
|
||
| if (reconnectionDelayMultiplier != other.reconnectionDelayMultiplier) return false | ||
| if (maxRetries != other.maxRetries) return false | ||
| if (initialReconnectionDelay != other.initialReconnectionDelay) return false | ||
| if (maxReconnectionDelay != other.maxReconnectionDelay) return false | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun hashCode(): Int { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the hashCode() ordering doesn't match the equals() ordering (reconnectionDelayMultiplier first vs. last), which is a style inconsistency even if not a correctness bug.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| var result = reconnectionDelayMultiplier.hashCode() | ||
| result = 31 * result + maxRetries | ||
| result = 31 * result + initialReconnectionDelay.hashCode() | ||
| result = 31 * result + maxReconnectionDelay.hashCode() | ||
| return result | ||
| } | ||
|
|
||
| override fun toString(): String = | ||
| "ReconnectionOptions(initialReconnectionDelay=$initialReconnectionDelay, maxReconnectionDelay=$maxReconnectionDelay, reconnectionDelayMultiplier=$reconnectionDelayMultiplier, maxRetries=$maxRetries)" | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also advantageous to have a jitter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, will consider in follow-up