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

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 change the initial Inet accumulator from internal_inet_values() to [] since those values are already appended in the connect and listen call sites.

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   25m 58s ⏱️
  819 tests   773 ✅  46 💤 0 ❌
4 274 runs  3 317 ✅ 957 💤 0 ❌

Results for commit adf3f59.

♻️ 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.

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 change the initial Inet accumulator from
internal_inet_values() to [] since those values are already appended
in the connect and listen call sites.

Signed-off-by: Viktor Söderqvist <[email protected]>
@zuiderkwast zuiderkwast force-pushed the ssl-inet-backend-preserve-order branch from f65d56b to adf3f59 Compare March 25, 2026 16:35
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 testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants