GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Stop the open-uri test server racing its own socket close by aminmansuri · Pull Request #9718 · jruby/jruby

Conversation

@aminmansuri

@aminmansuri aminmansuri commented Sep 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

SimpleHTTPSServer#shutdown closed the listening socket while its own thread
was blocked in accept, so the thread died on an IOError its rescue does
not cover and assert_join_threads failed the test. Intermittent because the
thread may instead be in the handshake, where the error is rescued.

CRuby kills the thread before closing for all three servers here; JRuby had
that commented out for this one. Kill is asynchronous, so the thread is also
joined, and the join is guarded — a bare one runs in the client thread's
ensure, masking the test's own failure, which is why one was removed from
this method in April 2025. net/http/utils.rb already does kill-then-join.

Refs #9276 — the same failure shape in this file's plain HTTP server.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aminmansuri
Stop the open-uri test server racing its own socket close
6ca8e2d
SimpleHTTPSServer closed its listening socket while its own thread was
still blocked in accept, so the thread died on the teardown. Kill the
thread and join it before closing, with the join guarded.
@aminmansuri

aminmansuri commented Sep 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

This is the one discovered during #9716

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

headius
headius reviewed Sep 20, 2026
View reviewed changes

@headius headius left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This one also needs a deeper look.

This file is part of the MRI test suite copied from CRuby, so usually we don't like to make changes here. Obviously I did that already by removing the @thread.kill.

There's clearly something wrong with the sequence of events here when running on JRuby, so there's two possibilities I see:

  • JRuby is doing something wrong internally that makes the kill+close sequence fail. In that case, JRuby should be fixed.
  • The test is making assumptions about the kill+close sequence that it should not, in which case the test should be fixed.

You and I have attempted to fix the test, but I have always wanted more confidence that it's not a JRuby bug we're patching around.

The test fix might be the right way to go, but in that case we should also try to get this into open-uri.

I'd propose the following:

  • Use the example case to determine whether JRuby is at fault. JRuby's full parallelism might make the test flaky (not our fault perhaps) or we might have a flaw in that event-passing that makes the test flaky.
  • If we can agree JRuby is not at fault, we should raise an issue with open-uri that this simplistic server teardown needs a patch.
  • Once accepted by open-uri we can patch it here and most likely it won't get wiped out by future updates.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@headius

headius commented Sep 20, 2026

Copy link
Copy Markdown
Member

A litte background here:

This simple server logic is now sprinkled over various parts of the CRuby test suite after the WEBrick library got moved out of the default stdlib. Formerly, WEBrick was used to manage these test servers, and it has much more robust logic for starting up and shutting down servers. I've never been quite satisfied with the new tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aminmansuri

aminmansuri commented Sep 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There is an example of the teardown you would want in test/mri/net/http/utils.rb — @thread.kill followed by @thread.join — and it still fails intermittently on JRuby. Two tests errored that way on #9718's own CI run, TestNetHTTPKeepAlive#test_keep_alive_get_auto_retry and TestNetHTTP_v1_2#test_get__implicit_start, both Errno::EBADF raised from IO#close at line 35, the socket&.close in the ensure inside the accept loop. The thread is killed, unwinds into that ensure, the close raises, and join re-raises it into the test. Java 21 and Java 26 failed; Java 25 passed on the same commit.

That may be the better case to reason from, since the kill and join are already there, so nothing can be blamed on their absence.

The teardown — @thread&.kill then @thread&.join:

jruby/test/mri/net/http/utils.rb

Lines 47 to 50 in 6718ce1

def shutdown
@thread&.kill
@thread&.join
end

The accept loop, with the socket&.close that raises at L35:

jruby/test/mri/net/http/utils.rb

Lines 28 to 39 in 6718ce1

def start
@thread = Thread.new do
loop do
socket = (@ssl_server || @server).accept
run(socket)
rescue
ensure
socket&.close
end
ensure
(@ssl_server || @server).close
end

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aminmansuri

aminmansuri commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Reported JRuby issue as #9722.

This one is separate: the open-uri teardown closes the server socket under a blocked accept with no kill, which raises on CRuby too — the helper's assumption, not an engine difference.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius

headius commented Oct 2, 2026

Copy link
Copy Markdown
Member

@aminmansuri Clarify for me what's left to do here... with the EBADF fix from #9723 do we still need this change?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aminmansuri

aminmansuri commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Yes, still needed. They fix different things.

#9723 fixed close after a thread is killed. This PR is about a server that is never killed: shutdown closes the socket while the thread is still waiting in accept. That raises IOError, on CRuby too, and the thread's rescue doesn't catch it, so the test fails.

The fix does what CRuby does here: kill the thread first, then close.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aminmansuri

aminmansuri commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

looking at the code should I put a

@thread.join(10)

To prevent a weird hang?

If no timeout it could, under some very rare circumstances block forever.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius

headius commented Oct 2, 2026

Copy link
Copy Markdown
Member

Ok, then we're back to my original problem with this change: why do we need to do it this way and CRuby just does

  def shutdown
    @thread.kill
    @server.close
  end

These tests are synced from CRuby (which syncs with ruby/openuri, see https://github.com/ruby/open-uri/blob/master/test/open-uri/utils.rb#L29-L32) so any changes we make in our copy can easily get wiped out by future updates.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius

headius commented Oct 8, 2026

Copy link
Copy Markdown
Member

@aminmansuri If you're still out there I'm still interested in resolving this. The ideal situation is to be able to use CRuby's test without modifications, but only if the setup+teardown it includes is expected to work properly on JRuby. If there's a problem with the test, we need to upstream that along with our local changes, so those changes don't get wiped out.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aminmansuri

aminmansuri commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I'm traveling right now so I can't get to it for a while.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius headius mentioned this pull request Oct 30, 2026
Handle OpenURI HTTPS listener shutdown race on JRuby #9962
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@headius headius headius left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@aminmansuri @headius
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.