Skip to content

Fix unhandled synchronous throw from WebSocket ConnectAsync - #15783

Merged
Julio César Rocha (JunielKatarn) merged 5 commits into
microsoft:mainfrom
jurocha-ms:OC/11296967/wsconex
Mar 16, 2026
Merged

Fix unhandled synchronous throw from WebSocket ConnectAsync#15783
Julio César Rocha (JunielKatarn) merged 5 commits into
microsoft:mainfrom
jurocha-ms:OC/11296967/wsconex

Conversation

@JunielKatarn

@JunielKatarn Julio César Rocha (JunielKatarn) commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

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
Julio César Rocha (JunielKatarn) merged commit 40efcf3 into microsoft:main Mar 16, 2026
32 checks passed
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (JunielKatarn) deleted the OC/11296967/wsconex branch March 17, 2026 01:01
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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
Julio César Rocha (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