Skip to content

FIXED unobserved exceptions surfacing due to unobserved tcs.#1051

Merged
mtmk merged 1 commit into
nats-io:mainfrom
me064:fix-unobserved-exceptions-from-tcs
Jan 28, 2026
Merged

FIXED unobserved exceptions surfacing due to unobserved tcs.#1051
mtmk merged 1 commit into
nats-io:mainfrom
me064:fix-unobserved-exceptions-from-tcs

Conversation

@me064

@me064 me064 commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Resolves #1050

Fixed unobserved exceptions surfacing from TaskCompletionSource objects setting exceptions but not observing them.

The fix includes an extension method TrySetObservedException for TaskCompletionSource that sets the exception and immediately observes it to avoid any unobserved exceptions. All usages of TrySetException has been replaced with TrySetObservedException.

Two new tests have been added and one unrelated test has been modified due to it causing unobserved exceptions that are then caught in one of the new tests, causing it to fail.

My recommendation for the future would be to create a global garbage collection test or similar to ensure no future unobserved exceptions appear throughout the library.

@mtmk

mtmk commented Jan 26, 2026

Copy link
Copy Markdown
Member

@me064 thanks for the PR it's looking good. The test seems to be failing for some reason. Once you fix the test I can have one last look then merge.

@me064
me064 marked this pull request as draft January 27, 2026 13:39
Signed-off-by: me064 <johannes.kull93@gmail.com>

Fixed unobserved exceptions from ProtocolTest surfacing in AuthErrorTest

minor improvements

Signed-off-by: me064 <johannes.kull93@gmail.com>
@me064
me064 force-pushed the fix-unobserved-exceptions-from-tcs branch from 25fa671 to 0a4fb1e Compare January 27, 2026 14:35
@me064
me064 marked this pull request as ready for review January 27, 2026 14:42

@mtmk mtmk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM thanks @me064

@mtmk
mtmk merged commit 49d5af8 into nats-io:main Jan 28, 2026
21 of 22 checks passed
mtmk added a commit that referenced this pull request Jan 30, 2026
* Fix OTel activity leak in Direct request mode (#1047)
* Fix subject UTF-8 encoding (#1054)
* Add SlowConsumerDetected event and warnings (#1052)
* Fixed unobserved exceptions surfacing due to unobserved tcs. (#1051)
@mtmk mtmk mentioned this pull request Jan 30, 2026
mtmk added a commit that referenced this pull request Jan 30, 2026
* Fix OTel activity leak in Direct request mode (#1047)
* Fix subject UTF-8 encoding (#1054)
* Add SlowConsumerDetected event and warnings (#1052)
* Fixed unobserved exceptions surfacing due to unobserved tcs. (#1051)
mtmk added a commit that referenced this pull request Feb 10, 2026
Changes in this release:
* Fix StreamSourceInfo.Active handle -1 correctly (#1058)
* Fix NatsUri not reflecting host/port changes from OnConnectingAsync hook (#997)

Chanfes from preview.2
* Fix OTel activity leak in Direct request mode (#1047)
* Fix subject UTF-8 encoding (#1054)
* Add SlowConsumerDetected event and warnings (#1052)
* Fixed unobserved exceptions surfacing due to unobserved tcs. (#1051)

Changes from preview.1
* Fix and improve build for docs ci error (#1040)
* resolves: 1035 - Use ConnectTimeout when awaiting INFO signal (#1039)
* Fix slow consumer blocking (#1041)
@mtmk mtmk mentioned this pull request Feb 10, 2026
mtmk added a commit that referenced this pull request Feb 10, 2026
Changes in this release:
* Fix StreamSourceInfo.Active handle -1 correctly (#1058)
* Fix NatsUri not reflecting host/port changes from OnConnectingAsync hook (#997)

Chanfes from preview.2
* Fix OTel activity leak in Direct request mode (#1047)
* Fix subject UTF-8 encoding (#1054)
* Add SlowConsumerDetected event and warnings (#1052)
* Fixed unobserved exceptions surfacing due to unobserved tcs. (#1051)

Changes from preview.1
* Fix and improve build for docs ci error (#1040)
* resolves: 1035 - Use ConnectTimeout when awaiting INFO signal (#1039)
* Fix slow consumer blocking (#1041)
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.

Authorization violation when connecting followed by recreating said connection causes unobserved SocketClosedException

2 participants