Skip to content

Send close_notify when closing an SSL connection on JRuby - #4029

Merged
joshuay03 merged 2 commits into
puma:mainfrom
IslamElsayed:jruby-ssl-close-notify
Sep 28, 2026
Merged

joshuay03 merged 2 commits into
puma:mainfrom
IslamElsayed:jruby-ssl-close-notify

Conversation

@IslamElsayed

Copy link
Copy Markdown
Contributor

Description

Since 09-27 the four JRuby jobs on main fail TestPumaControlCli#test_control_ssl_ipv4 and _ipv6, with pumactl printing closing inbound before receiving peer's close_notify in place of Command stop sent success. The last green run, on 09-16, used JRuby 10.1.1 with jruby-openssl 0.19.1. The first red run used JRuby 10.1.2 with jruby-openssl 0.19.2, whose release notes include "reject unexpected TLS EOFs unless OP_IGNORE_UNEXPECTED_EOF is enabled". The only puma commit in between, #4027, touches mini_ssl.c, which JRuby doesn't use.

The client is right to complain: on JRuby, puma closes an SSL connection without sending close_notify. MiniSSL::Socket#close calls @engine.shutdown and, when it returns false, sends whatever @engine.extract hands back. The C engine's SSL_shutdown queues the alert, but the Java shutdown never called closeOutbound() on an open connection, so there was nothing to extract. It only called it in the branch where outbound was already done, where it does nothing.

This makes the Java shutdown behave like the C one:

  • On an open connection, call closeOutbound() and wrap once, so the alert is waiting for #extract.
  • Send nothing if the handshake never finished, as the C engine does with its SSL_in_init check. Without this, test_http_rejection fails, because a plain-HTTP client would get TLS alert bytes instead of EOF.

MRI is unaffected; the change is Java only.

Testing

Locally on JRuby 10.1.2 with Temurin 21.0.12 and jruby-openssl 0.19.2, the same versions CI uses:

  • test/test_pumactl.rb -n /control_ssl/: 2 failures on main, passing with this change.
  • test_puma_server_ssl.rb (23 runs), test_pumactl.rb, test_minissl.rb and test_integration_ssl.rb all pass.
  • test_integration_pumactl.rb's *_unix tests fail on my machine with and without this change, so they are local and unrelated.

This should also clear the red JRuby jobs on open PRs, including #4028.

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature. (The existing test_control_ssl_* tests are the regression tests; test_http_rejection covers the handshake guard.)
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

I use AI assistance when working on patches, and I check and test everything before submitting.

MiniSSL::Engine#shutdown never called closeOutbound on an open connection, so
MiniSSL::Socket#close had no close_notify alert to send and the socket closed
without one. jruby-openssl 0.19.2 now rejects a TLS stream that ends that way,
which broke pumactl's SSL stop command (test_control_ssl_ipv4/_ipv6).
@github-actions github-actions Bot added the waiting-for-review Waiting on review from anyone label Sep 27, 2026

@joshuay03 joshuay03 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@github-actions github-actions Bot added waiting-for-merge Approved and waiting to be merged and removed waiting-for-review Waiting on review from anyone labels Sep 28, 2026
@joshuay03
joshuay03 force-pushed the jruby-ssl-close-notify branch from f510eff to 1fc38d8 Compare September 28, 2026 09:13
@joshuay03
joshuay03 merged commit 3e98761 into puma:main Sep 28, 2026
5 of 62 checks passed
lewispb added a commit to basecamp/puma that referenced this pull request Sep 28, 2026
…view

* puma-upstream/main:
  Run Ragel generation check on Ubuntu only (puma#4030)
  Fix wakeup deadlock (puma#4025)
  Send close_notify when closing an SSL connection on JRuby (puma#4029)
  Separate unit and integration test commands (puma#3989)
  Fix NoMethodError when a malformed request has no request line (puma#3992)
nateberkopec pushed a commit to nateberkopec/puma that referenced this pull request Nov 8, 2026
nateberkopec added a commit that referenced this pull request Nov 9, 2026
* Fix flaky TestOutOfBandServer#test_stream

Each app call waited on @app_finished with a 1s timeout. When the server
accepted connections slower than the app threads drained them, a waiting
thread timed out, both threads went idle, and the out-of-band hook fired
mid-stream, so @oob_count ended up 2.

Wait until the next request arrives or the test releases the app instead
of timing out. On JRuby this failed 29 of 51 runs; it now passes 150 of 150.

AI-assisted: claude-opus-5-5; thinking high
(cherry picked from commit e789c8c)

* Regenerate expired chain cert and fix its expiry check (#4039)

The chain cert generator didn't set a validity period on the leaf cert,
so it expired after the library's one year default while the CAs last
four. The expiry test also compared against 30 days ago instead of 30
days from now, so it only failed a month after a cert expired.

(cherry picked from commit 36b6033)

* ci: test_error_logger.rb - fix TruffleRuby error (#3930)

(cherry picked from commit 97996aa)

* ci: test_puma_server_ssl.rb - fix two cipher suite tests (#3878)

(cherry picked from commit 604be67)

* ci: remove client `ctx.ssl_version` code from tests (#3981)

(cherry picked from commit e451ff9)

* Send close_notify when closing an SSL connection on JRuby (#4029)

Co-authored-by: Joshua Young <[email protected]>
(cherry picked from commit 3e98761)

* ci: integration.rb - fixup restart_does_not_drop_connections in single mode (#3955)

Fixes recent errors like:
```
  1) Failure:
TestIntegrationSingle#test_hot_restart_does_not_drop_connections_threads [test/helpers/integration.rb:636]:
      0 unexpected_response
      0 refused
      0 read timeout
      0 reset
      0 write_errors
   1000 success
    220 success after restart
      1 restart count
.
Expected 1 to be >= 2.
Fixes recent errors like:

  1) Failure:
TestIntegrationSingle#test_hot_restart_does_not_drop_connections_threads [test/helpers/integration.rb:636]:
      0 unexpected_response
      0 refused
      0 read timeout
      0 reset
      0 write_errors
   1000 success
    220 success after restart
      1 restart count

Expected 1 to be >= 2.
```
Only changes behavior with 'single' runs.

(cherry picked from commit dc972ef)

* Run Ragel generation check on Ubuntu only (#4030)

(cherry picked from commit d2aa78a)

* Increase timeout for Intel JRuby tests to 12 minutes (#3876)

Intel macOS runners are slower than ARM, causing test timeouts at 8 minutes.
Recent failures show tests hitting timeouts and retries before the overall
action timeout is reached.

Co-authored-by: Claude Sonnet 4.5 <[email protected]>
(cherry picked from commit fde728e)
AI-assisted: claude-opus-5-5; thinking high

* ci: drop retired macos-14 runners

GitHub retired the macos-14 runner image on 2026-11-02, so every
macos-14 job is now cancelled before it starts. Remove macos-14 from
the test matrix and move the arm64 macOS JRuby job to macos-26.

AI-assisted: claude-opus-5-5; thinking high

* Fix -Wshorten-64-to-32 errors on Windows arm64 Ruby head (#4071)

Ruby head now defines rb_len_t as a 64-bit type on Windows, where long
is 32 bits. Cast the string length explicitly, and convert the size_t
nread values with SIZET2NUM.

AI-assisted: claude-opus-5-5; thinking high

---------

Co-authored-by: Joshua Young <[email protected]>
Co-authored-by: MSP-Greg <[email protected]>
Co-authored-by: Islam Elsayed <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
nateberkopec added a commit to nateberkopec/puma that referenced this pull request Nov 11, 2026
Co-authored-by: Joshua Young <[email protected]>
(cherry picked from commit 3e98761)

AI-assisted: claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-merge Approved and waiting to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants