Skip to content

Settle start() with the outcome of an initialization retry - #1924

Merged
Dirk Bäumer (dbaeumer) merged 4 commits into
microsoft:mainfrom
trivikr:client-settle-start
Oct 30, 2026
Merged

Dirk Bäumer (dbaeumer) merged 4 commits into
microsoft:mainfrom
trivikr:client-settle-start

Conversation

@trivikr

Copy link
Copy Markdown
Contributor

When initialize failed and the client retried, either because initializationFailedHandler returned true or because the user picked Retry for an InitializeError with retry: true, doInitialize started the retry in the background and rethrew. start() rejected and the client moved to StartFailed. A successful retry then switched the client to Running while start() had already rejected, and later start() calls kept returning that rejected promise. A failed retry rejected a promise nobody observed, so it surfaced as an unhandled rejection.

Return the retry from doInitialize, and await the Retry choice, so start() resolves or rejects once with the result of the last attempt. Stop the client in one place after a failed initialization is not retried. For a retryable InitializeError without a handler, start() now stays pending until the user answers the Retry message instead of rejecting while it is shown. Add integration tests for a successful and a failed retry through initializationFailedHandler and through the Retry message.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@trivikr

Copy link
Copy Markdown
Contributor Author

Some history on why doInitialize retried in the background:

  • c2f0c87 (2015) added the retry. Readiness was reported through onReady(), which the success path resolved and the give-up paths rejected. Starting the retry without awaiting it was fine then: onReady() stayed pending through the Retry dialog and settled with the retry's outcome.
  • 0ddb66e (2019, "Move to promise instead of thenable") added throw error; at the end of the error handler. The rejection then reached start()'s catch, which set StartFailed and rejected onReady() while the retry was still running. This is where it broke.
  • f97bb73 (2022) replaced onReady() with the promise returned by start(). It kept the background retry and the rethrow, so nothing tied the retry's outcome to the caller anymore.

So start() waiting for the Retry choice isn't new behavior. It restores how onReady() worked before 0ddb66e.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Connection closure while the Retry prompt is open can leave existing startup promises pending until the user responds.

2 open issues

Review effort: Balanced

Comment thread client/src/common/client.ts Resolved
Comment thread client/src/common/client.ts Resolved
@dbaeumer

Copy link
Copy Markdown
Member

Trivikram Kamat (@trivikr) see the Copilot review comments. Especially the first one seems valid to me.

When initialize failed and the client retried, either because
initializationFailedHandler returned true or because the user picked
Retry for an InitializeError with retry: true, doInitialize started the
retry in the background and rethrew. start() rejected and the client
moved to StartFailed. A successful retry then switched the client to
Running while start() had already rejected, and later start() calls kept
returning that rejected promise. A failed retry rejected a promise
nobody observed, so it surfaced as an unhandled rejection.

Return the retry from doInitialize, and await the Retry choice, so
start() resolves or rejects once with the result of the last attempt.
Stop the client in one place after a failed initialization is not
retried. For a retryable InitializeError without a handler, start() now
stays pending until the user answers the Retry message instead of
rejecting while it is shown. Add integration tests for a successful and
a failed retry through initializationFailedHandler and through the Retry
message.
start() waits for the user to answer the Retry message of a retryable
InitializeError. If the server exited while the message was shown, the
close handling moved the client to StartFailed, or restarted it, but
the pending start() calls stayed unsettled until the user answered a
message for a connection that was already gone. Answering it then acted
on the stale connection: Retry sent initialize on the disposed
connection, and dismissing stopped the client, which after a restart
was the new one.

Race the Retry message against the connection closing, and reject the
start without stopping the client when the connection closes first,
ignoring a later answer. Only mark the client as StartFailed when the
failing start is still the current one, so a late rejection doesn't
override a restart. Add an integration test with a server that exits
while the Retry message is open.
The tests for a failed retry used a server that refused every
initialization with the same error, so they couldn't show that start()
rejects with the error of the last attempt, and no test covered a
failed retry chosen from the Retry message.

Add a server that asks for a retry and then fails it with a distinct
error. Use it for the initializationFailedHandler retry test, and add a
test that picks Retry from the message and checks that start() rejects
with the final error, the client is stopped once, and no rejection is
unhandled.
@trivikr

Copy link
Copy Markdown
Contributor Author

Trivikram Kamat (Trivikram Kamat (@trivikr)) see the Copilot review comments.

Dirk Bäumer (@dbaeumer) I incorporated suggestions from both comments, and pushed commits.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the startup retry and connection-closure changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 29, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the startup initialization retry changes.

No open issues 🎉

Review effort: Balanced

@dbaeumer
Dirk Bäumer (dbaeumer) merged commit bf7b394 into microsoft:main Oct 30, 2026
5 checks passed
@dbaeumer Dirk Bäumer (dbaeumer) added this to the 3.18.6 milestone Nov 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.

5 participants