Commit Graph

18 Commits

Author SHA1 Message Date
Fabian @ Blax Software 35ed320202 fix(fork): children never outlive the server or hold its port (#2465)
A fork-per-message child inherits the server's listening socket. A child
that outlived the server (a long-running handler such as an engine loop)
kept the port bound, so the restarted server failed with EADDRINUSE until
that child died.

- Track every forked child (Server\ChildProcesses). On hard and soft
  shutdown, send SIGTERM to the ones still running, SIGKILL them after
  websockets.shutdown.child_grace_seconds (default 2) and reap them. A PID is
  signalled only while waitpid() confirms it is still an unreaped child, with
  SIGCHLD blocked, so a recycled PID is never hit. Opt out with
  websockets.shutdown.terminate_children = false.
- Right after fork the child closes its copy of the listening socket, so even
  a stray child cannot hold the port. Only the fd is closed: the React server
  is not closed, because removing it from an ext-ev/ext-event loop would edit
  the epoll set the child shares with the parent.
- The child restores default SIGTERM/SIGINT/SIGCHLD handling. Under ext-ev
  the inherited libev handlers swallowed SIGTERM in the child.
- A child that dies of a fatal error (out of memory, E_ERROR) now sends
  <event>:error from a shutdown function (Server\ChildFatalErrorGuard,
  #1462). A child that dies without any reply (killed by a signal, or the
  shutdown function never ran) gets <event>:error from the parent, decided
  once both its stream and its exit status are in
  (Websocket\ChildMessageOutcome).
- Tests: real forks, signals and sockets for the shutdown, the port release
  and the fatal reply; end to end through Handler::forkWithSocketPair(). The
  test TestCase now stops a leftover broadcast socket, which made
  ws_available() true for later tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-14 10:38:11 +02:00
Fabian @ Blax Software c169e418ca fix(shutdown): soft shutdown always stops the loop
The soft shutdown chained ->then() on Handler::onClose(), which returns
void. The error became a silently dropped promise rejection, loop->stop()
never ran, and the server kept accepting and closing every new socket
without connection_established until a hard restart. Clients queued their
sends forever in that window.

- Close connections directly (Ratchet runs onClose once per stream), stop
  the loop after a 1s grace, on a listing error, or at a 5s deadline.
- Websocket\ChannelManager::unsubscribeFromAllChannels returns early for a
  connection declined before it got an app, like LocalChannelManager. That
  was the "Attempt to read property id on null" flood in the log.
- Tests: SoftShutdownTest drives the shutdown on a fresh loop, StartServerTest
  fails on any error logged during a soft shutdown, ClosedBeforeOpenTest.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 14:20:46 +02:00
Fabian @ Blax Software 093bbe3a44 A tests, documentation for helpers and lifecycle
- Introduced `helpers-and-testing.md` to document global helpers and WebsocketService class usage.
- Created `HandlerLifecycleTest.php` to test the full WebSocket handler lifecycle, including connection management, channel subscriptions, and message routing.
- Added `WebsocketServiceTest.php` to validate state tracking methods in WebsocketService, covering user authentication, channel tracking, and broadcast functionality.
2026-04-02 12:44:16 +02:00
Alexander Blasl 1a5db82c26 Renovation 2025-01-16 08:54:02 +01:00
Alex Renoki ec47925c71 Added soft closes for connections on SIGTERM/SIGINT 2020-09-12 17:45:07 +03:00
rennokki 341eb9604f
Apply fixes from StyleCI (#518) 2020-09-10 21:59:49 +02:00
Alex Renoki 6f32b89459 wip 2020-09-10 22:59:26 +03:00
Alex Renoki 3fcfe1bb39 Added test for app_id 2020-08-23 13:44:09 +03:00
Alex Renoki 92870c088a wip 2020-08-22 21:54:48 +03:00
rennokki 16446309ca
Apply fixes from StyleCI (#449) 2020-08-13 13:25:10 +02:00
Alex Renoki 344dfa7f96 Added --test for websockets:serve command 2020-08-13 14:21:06 +03:00
zaxxo-dkraemer 0915132369 Add restart command for WebSocket server 2020-08-13 10:09:55 +02:00
Freek Van der Herten fa0bd1c9ef
Apply fixes from StyleCI (#329) 2020-03-04 10:58:39 +01:00
Francis Lavoie 3ec6c0ade3 Add support for Laravel 5.8 (#122)
* Fix Laravel 5.8 compatibility

* Use Arr:: and Str:: instead of global helpers

* Remove testbench-core dependency, release was tagged
2019-02-27 15:27:21 +01:00
Marcel Pociot 9ce2cc3ff7
Apply fixes from StyleCI (#3) 2018-12-04 22:22:33 +01:00
freek d9a831be86 wip 2018-12-04 21:03:26 +01:00
freek 882c060817 nitpicks 2018-12-04 20:59:43 +01:00
Marcel Pociot f89278ede1 wip 2018-12-04 11:48:07 +01:00