Commit Graph

91 Commits

Author SHA1 Message Date
Fabian @ Blax Software b066d75b33 BF reject private/presence subscribe with invalid signature
handleSubscription() recorded the socket in $channel_connections and in the
buffered ws_channel_connections_* / ws_active_channels cache before
$channel->subscribe() ran, and swallowed the InvalidSignature it threw. On
the same frame shouldRejectMessage() found the entry and called
saveConnection(), and the client got "websocket.subscribe:response Success".
One subscribe with a bad signature put the socket on the private or presence
channel, where it received broadcasts, and WebsocketService listed it.

- Track the socket only after subscribe() succeeds (or it is already on the
  channel).
- A failed private/presence subscribe answers "<event>:error" with the
  exception's message and code (Invalid Signature, 4009), drops any earlier
  tracking of the socket on that channel, takes it off the channel if the
  subscribe had already saved it, and ends the frame before
  shouldRejectMessage() and the Success reply.
- Public channels behave as before.

Tests assert, after the single subscribe frame, the error reply, no channel
membership, no $channel_connections entry and no cache listing, and that a
later message on the channel does not resubscribe the socket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 11:56:38 +01:00
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 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
Fabian @ Blax Software 5b8a2a8112 I performance, A testing & event-driven 2026-01-24 13:34:29 +01:00
Blax Software 87bf0ae05e Pusher : -> . 2025-01-18 17:06:52 +01:00
Alexander Blasl 1a5db82c26 Renovation 2025-01-16 08:54:02 +01:00
Marcel Pociot 2e4b2f35f9
Apply fixes from StyleCI (#1190) 2024-02-07 18:30:54 +01:00
Marcel Pociot fb958fb851
Merge 2.x changes (#1043)
* Resolve conflicts

* Apply fixes from StyleCI (#1042)
2022-10-06 13:46:54 +02:00
Marcel Pociot fd2070fc3d update tests 2022-01-06 12:31:21 +01:00
erikn69 0a8f7aa33e
Fix on tests (#895) 2021-12-17 16:42:26 +01:00
Alex Renoki c43a9d4d46 Fixed Routes registration 2021-04-06 17:21:15 +03:00
Alex Renoki fd1a459047 Added integrations for Redis 2020-09-26 10:30:53 +03:00
Alex Renoki c1bef4db5b Added async redis connection 2020-09-25 22:16:06 +03:00
Alex Renoki 5cb2ee9fce Run promises one-after-another 2020-09-19 14:16:26 +03:00
Alex Renoki b41f8b7b75 Creating SignedMessage class for testing 2020-09-15 20:46:19 +03:00
Alex Renoki df45ee89ff Clearing assertions on each test 2020-09-15 17:03:28 +03:00
Alex Renoki f04cce73d3 Added websockets:flush command 2020-09-11 16:39:56 +03:00
Alex Renoki be9e21e518 wip 2020-09-11 15:57:51 +03:00
Alex Renoki dfe0dbf335 Updated mode 2020-09-11 15:19:15 +03:00
Alex Renoki 25af2ee701 Fixed migrations for tests 2020-09-11 08:47:28 +03:00
Alex Renoki 375078e686 doctrine/dbal 2020-09-11 08:16:53 +03:00
Alex Renoki 666ecb04f2 wip 2020-09-10 23:26:32 +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 7e9d3cdc77 Fixed tests 2020-09-04 22:38:01 +03:00
Alex Renoki cadd2602cb Merge branch 'fix/app-connections-count' of github.com:beyondcode/laravel-websockets into fix/app-connections-count 2020-09-04 22:35:38 +03:00
Alex Renoki 7a629cfcb0 Fixed typo 2020-09-04 22:35:35 +03:00
rennokki b2ac9090cc
Apply fixes from StyleCI (#503) 2020-09-04 21:28:42 +02:00
Alex Renoki 1e2672d9e0 Updated tests 2020-09-04 22:26:46 +03:00
Alex Renoki ea9741072b Fixed tests 2020-09-04 21:50:38 +03:00
Alex Renoki e6cfa85472 Replaced blocking Redis instance with non-blocking I/O client 2020-09-04 17:50:49 +03:00
Alex Renoki fadb3fc123 Added redis connection counter. 2020-09-03 16:31:19 +03:00
Alex Renoki 0dfa682c97 Revert "Moved all websockets testing related stuff into a concern"
This reverts commit aa014add21.
2020-08-31 11:06:14 +03:00
Alex Renoki bb5599f6cd Revert "Fixed tests"
This reverts commit 6ddf5900e2.
2020-08-31 11:05:41 +03:00
Alex Renoki 6ddf5900e2 Fixed tests 2020-08-31 10:22:41 +03:00
Alex Renoki aa014add21 Moved all websockets testing related stuff into a concern 2020-08-30 20:01:08 +03:00
rennokki 08110b652e
Apply fixes from StyleCI (#493) 2020-08-28 18:45:18 +02:00
Alex Renoki 5b6bdf49e4 Added configurable client for each replication driver. 2020-08-28 19:44:54 +03:00
rennokki edcc2f9582
Apply fixes from StyleCI (#491) 2020-08-27 21:13:50 +02:00
Alex Renoki 0c8c5c0d9b Moved the mocks statistics loggers to Mocks/ 2020-08-27 22:13:30 +03:00
Alex Renoki a897ce2cd3 Fixed backend streaming 2020-08-27 14:13:17 +03:00
Alex Renoki f62ac8fd56 wip 2020-08-23 19:12:22 +03:00
Alex Renoki b46cfadaa2 wip 2020-08-23 18:34:29 +03:00
Alex Renoki 2a6d91aaf7 Added tests for statistics loggers drivers 2020-08-23 13:40:18 +03:00
Alex Renoki ce652bbbcb Mocked message expects array 2020-08-22 20:53:33 +03:00
rennokki b1597bb836
Apply fixes from StyleCI (#476) 2020-08-19 21:40:02 +02:00
Alex Renoki 99b55411c1 Removed controller that sends out the statistics 2020-08-19 22:39:38 +03:00
Alex Renoki a36d3366f1 Enforce DNS lookup on testing 2020-08-18 23:22:10 +03:00
Alex Renoki 0b412cd98e added docblocks 2020-08-18 20:21:22 +03:00
Alex Renoki 11727e684f Added cors setting outside the app 2020-08-18 16:04:52 +03:00