Skip to content

Fix unhandled synchronous throw from WebSocket ConnectAsync#15783

Merged
JunielKatarn merged 5 commits intomicrosoft:mainfrom
jurocha-ms:OC/11296967/wsconex
Mar 16, 2026
Merged

Fix unhandled synchronous throw from WebSocket ConnectAsync#15783
JunielKatarn merged 5 commits intomicrosoft:mainfrom
jurocha-ms:OC/11296967/wsconex

Conversation

@JunielKatarn
Copy link
Contributor

@JunielKatarn JunielKatarn commented Mar 16, 2026

Description

Handle synchronous exceptions from IMessageWebSocket::ConnectAsync.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

Unexpected WebSocket connection errors may cause a synchronous exception to be thrown, which is not converted into an HRESULT by the lessthrow_awiat_adapter because it only handles asynchronous exceptions originated during the coroutine suspend/resume cycle.

What

Add the ConnectAsync call to an existing try-catch handling block in the same code block.

Testing

Added test WinRTWebSocketResourceUnitTest::ConnectAsyncThrowsSynchronously.

Changelog

No

Microsoft Reviewers: Open in CodeFlow

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.
@JunielKatarn JunielKatarn enabled auto-merge (squash) March 16, 2026 22:25
@JunielKatarn JunielKatarn merged commit 40efcf3 into microsoft:main Mar 16, 2026
32 checks passed
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 17, 2026
…t#15783)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
@JunielKatarn JunielKatarn deleted the OC/11296967/wsconex branch March 17, 2026 01:01
JunielKatarn added a commit that referenced this pull request Mar 17, 2026
…15796)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit that referenced this pull request Mar 17, 2026
…15791)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit that referenced this pull request Mar 17, 2026
…15789)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit that referenced this pull request Mar 17, 2026
…15788)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
JunielKatarn added a commit that referenced this pull request Mar 17, 2026
…15790)

* Fix unhandled synchronous throw from ConnectAsync

(Generated summary)
ConnectAsync can throw synchronously (e.g. WININET_E_INVALID_CA /
0x80072EE1 on certificate validation failure) before returning an
IAsyncAction. Move the call inside the existing try/catch block so
such exceptions are routed through Fail() instead of propagating
unhandled. Add ConnectAsyncThrowsSynchronously unit test to cover
this path.

* Change files

* Add explaining comment

* clang format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants