Skip to content

Use raw zmq_proxy for ffi-rzmq heartbeat - #391

Merged
kojix2 merged 3 commits into
SciRuby:masterfrom
kojix2:fix-ffirzmq-heartbeat-exit-hang-2
Jun 6, 2026
Merged

Use raw zmq_proxy for ffi-rzmq heartbeat#391
kojix2 merged 3 commits into
SciRuby:masterfrom
kojix2:fix-ffirzmq-heartbeat-exit-hang-2

Conversation

@kojix2

@kojix2 kojix2 commented Jun 5, 2026

Copy link
Copy Markdown
Member
  • Replace ZMQ::Device with LibZMQ.zmq_proxy
  • Stop heartbeat with zmq_ctx_shutdown before closing sockets
  • Treat ETERM and EINTR from zmq_proxy as normal shutdown
  • Set zero linger on the ffi-rzmq heartbeat socket
  • Add a Session close test for the live heartbeat path

This addresses #357. The ffi-rzmq heartbeat still uses libzmq's proxy behavior, but avoids the ZMQ::Device wrapper and gives Session#close an explicit path to stop the heartbeat thread.

kojix2 added 2 commits June 5, 2026 09:14
- Replace ZMQ::Device with LibZMQ.zmq_proxy
- Stop heartbeat with zmq_ctx_shutdown before closing sockets
- Treat ETERM and EINTR from zmq_proxy as normal shutdown
- Set zero linger on the ffi-rzmq heartbeat socket
- Add a Session close test for the live heartbeat path

This addresses SciRuby#357. The ffi-rzmq heartbeat still uses libzmq's proxy
behavior, but avoids the ZMQ::Device wrapper and gives Session#close an
explicit path to stop the heartbeat thread.
@kojix2
kojix2 marked this pull request as ready for review June 5, 2026 00:27
@kojix2
kojix2 requested a review from Copilot June 5, 2026 00:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates IRuby’s session shutdown path to explicitly stop the ffi-rzmq heartbeat thread (addressing the Ruby 3.4 test-suite hang in #357) by avoiding the ZMQ::Device wrapper and adding an adapter hook to shut down the underlying libzmq proxy loop cleanly.

Changes:

  • Replace ZMQ::Device with a direct LibZMQ.zmq_proxy call in the ffi-rzmq heartbeat loop and treat ETERM/EINTR as normal shutdown.
  • Introduce SessionAdapter#shutdown_heartbeat and invoke it from Session#close prior to stopping the heartbeat thread.
  • Set LINGER=0 for the ffi-rzmq heartbeat (:REP) socket and add a test ensuring Session#close terminates the heartbeat thread.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/iruby/session.rb Adjusts shutdown ordering to request heartbeat shutdown before stopping thread and closing sockets.
lib/iruby/session_adapter.rb Adds shutdown_heartbeat hook to the adapter base API.
lib/iruby/session_adapter/ffirzmq_adapter.rb Uses raw zmq_proxy, adds context shutdown logic, and sets zero linger for heartbeat socket.
lib/iruby/session_adapter/test_adapter.rb Updates test adapter shutdown/close tracking to support the new heartbeat shutdown path.
test/iruby/session_test.rb Adds coverage ensuring the live ffi-rzmq heartbeat thread is not left running after Session#close.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/iruby/session_adapter/ffirzmq_adapter.rb
Comment thread lib/iruby/session_adapter/test_adapter.rb
Comment thread lib/iruby/session.rb

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@kojix2
kojix2 merged commit ee7ffea into SciRuby:master Jun 6, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants