Skip to content

ssl: Preserve inet option order in emulated_options#10908

Open
zuiderkwast wants to merge 1 commit intoerlang:maintfrom
zuiderkwast:ssl-inet-backend-preserve-order
Open

ssl: Preserve inet option order in emulated_options#10908
zuiderkwast wants to merge 1 commit intoerlang:maintfrom
zuiderkwast:ssl-inet-backend-preserve-order

Conversation

@zuiderkwast
Copy link
Copy Markdown
Contributor

@zuiderkwast zuiderkwast commented Mar 24, 2026

The emulated_options/3 function in tls_socket and dtls_socket used a prepend accumulator pattern without reversing the result, causing inet options to be reversed when passed to gen_tcp:connect/gen_udp:open.

This broke the inet_backend option which must be the first option in the list according to gen_tcp and gen_udp documentation.

Fix by reversing the Inet accumulator before returning.

Before

Erlang/OTP 28 [erts-16.1.2] [source] [64-bit] [smp:14:14] [ds:14:14:10] [async-threads:1] [jit] [dtrace]

Eshell V16.1.2 (press Ctrl+G to abort, type help(). for help)
1> application:ensure_all_started(ssl).
{ok,[crypto,asn1,public_key,ssl]}
2> ssl:connect("127.0.0.1", 12345, [{inet_backend, socket}, {recbuf, 32768}, {verify, verify_none}]).
{error,{badarg,"gen_tcp:connect(\"127.0.0.1\", 12345, [{recbuf,32768},{inet_backend,socket}], infinity)"}}
3> ssl:connect("127.0.0.1", 12345, [{inet_backend, socket}, {recbuf, 32768}, {protocol, dtls}, {verify, verify_none}], 1000).
** exception exit: badarg
     in function  inet_udp:open/2 (inet_udp.erl:56)
     in call from dtls_socket:connect/4 (dtls_socket.erl:92)
     in call from ssl:connect/4 (ssl.erl:2269)

After

Erlang/OTP 29 [RELEASE CANDIDATE 2] [erts-16.3] [source-c77b8b0c89] [64-bit] [smp:14:14] [ds:14:14:10] [async-threads:1] [jit]

Eshell V16.3 (press Ctrl+G to abort, type help(). for help)
1> application:ensure_all_started(ssl).
{ok,[crypto,asn1,public_key,ssl]}
2> ssl:connect("127.0.0.1", 12345, [{inet_backend, socket}, {recbuf, 32768}, {verify, verify_none}]).
{error,econnrefused}
3> ssl:connect("127.0.0.1", 12345, [{inet_backend, socket}, {recbuf, 32768}, {protocol, dtls}, {verify, verify_none}], 1000).
{error,timeout}

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

CT Test Results

    2 files     66 suites   26m 20s ⏱️
  819 tests   773 ✅  46 💤 0 ❌
4 276 runs  3 319 ✅ 957 💤 0 ❌

Results for commit c380a0d.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@IngelaAndin IngelaAndin self-assigned this Mar 25, 2026
@IngelaAndin IngelaAndin added team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI labels Mar 25, 2026
IngelaAndin
IngelaAndin previously approved these changes Mar 25, 2026
@IngelaAndin
Copy link
Copy Markdown
Contributor

@zuiderkwast Please base it so that it can be target for maint. (Or retarget if that is already the case) I think it is a bug that it does not work so we want to fix it for maint too.

@zuiderkwast zuiderkwast changed the base branch from master to maint March 25, 2026 16:32
@zuiderkwast zuiderkwast dismissed IngelaAndin’s stale review March 25, 2026 16:32

The base branch was changed.

@zuiderkwast zuiderkwast force-pushed the ssl-inet-backend-preserve-order branch from f65d56b to adf3f59 Compare March 25, 2026 16:35
@sverker sverker removed the testing currently being tested, tag is used by OTP internal CI label Mar 31, 2026
@sverker
Copy link
Copy Markdown
Contributor

sverker commented Mar 31, 2026

@IngelaAndin @zuiderkwast

Does not compile:

dtls_socket.erl:237:7: syntax error before: '{'
       {Inet ++ internal_inet_values(), Emulated}
       ^

@zuiderkwast
Copy link
Copy Markdown
Contributor Author

Sorry for the typo(s). Shall I squash the commits and force-push?

@IngelaAndin
Copy link
Copy Markdown
Contributor

@zuiderkwast Yes please could also make sure that you base your branch on OTP-28.4.1-label as then I can piggyback it on an un-planned OTP-28 patch, as there are no more planned patches for 28 track. (It can still be targeted at maint here as it should merge cleanly).

The emulated_options/3 function in tls_socket and dtls_socket used a
prepend accumulator pattern without reversing the result, causing inet
options to be reversed when passed to gen_tcp:connect/gen_udp:open.

This broke the inet_backend option which must be the first option in
the list according to gen_tcp and gen_udp documentation.

Fix by reversing the Inet accumulator before returning. For
dtls_socket, also append internal inet options to the user-provided
ones instead of prepending them.

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
@zuiderkwast zuiderkwast force-pushed the ssl-inet-backend-preserve-order branch from 53bd589 to c380a0d Compare April 2, 2026 15:44
@zuiderkwast
Copy link
Copy Markdown
Contributor Author

@IngelaAndin Done. It's based on the OTP-28.4.1 tag now.

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

Labels

team:PS Assigned to OTP team PS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants