ruby / ruby/spec

TCPSocket specs hang if client doesn't connect

Open
#925 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
622
Forks
402
Avg merge
14h 51m
Merged PRs (30d)
6

Description

The TCPSocket#initialize specs will hang if the client socket does not connect to the server, since the shutdown for the server expects that it will have handled a request and be wrapping up here:

https://github.com/ruby/spec/blob/master/library/socket/fixtures/classes.rb#L125-L129

I found this while adding support for the new connect_timeout keyword; we do not support hash arguments on TCPSocket#initialize at the moment, so the socket never connects. This leaves the server waiting for an incoming connection, and the Thread#join above will hang the suite.

Perhaps we should actively try to close the server socket before we join the thread, and ignore any errors on the thread from a double-close? It would allow these specs to be a bit more robust when there are errors setting up the TCPSocket before connection.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the TCPSocket fixture in library/socket/fixtures/classes.rb around lines 125-129, focusing on the server shutdown and the Thread#join. Run the TCPSocket#initialize specs with a client that fails to connect, then verify that closing the server before joining prevents the suite from hanging and handles any double-close error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
networking, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.