Commit Graph
70 Commits
Author SHA1 Message Date
andrey 49dc3cefe7 fix(picloud-dispatcher): drop data to a connection whose write is stalled
While the peer does not drain its receive buffer, every forwarded packet
would re-stall the reader thread for up to writeTimeout(), so a queued
Disconnect frame could wait behind the whole backlog. Remember a stalled
target (send slower than 2 s) and drop data for a short cooldown instead
of stalling; keep dispatcher writes bounded at 3 s. Control frames
(Connected/Disconnected) are unaffected.
2026-08-24 15:14:45 +03:00
andrey 22a09ddd1c fix(picloud-dispatcher): start read thread under the lock and drain rmrf_* in the destructor
newConnection pushed the client into clients while holding map_mutex
but started its read thread after releasing it; in that window the
client was a live member of clients with no read thread and could be
marked, closed and deleted by the drainer before start() ran. Start
the thread inside the locked section: the thread can only wait for
map_mutex after the function has released it, so this is not a
deadlock, and the 'everything in clients is started' invariant holds.

~DispatcherServer dropped clients/servers pending in rmrf_clients/
rmrf_servers without closing or deleting them (object leak of live
PIObjects). Collect them together with the main maps, then run the
same stop/close/delete sequence. The sets are disjoint with the main
maps by construction (items are removed from the main maps when
marked), so there are no duplicates.
2026-08-23 18:55:15 +03:00
andrey 1ec61a0127 fix(picloud-dispatcher): forward data to sub-client under mutex_clients
The dataReadedServer lambda looked up the sub-client under
mutex_clients but called sendData() after the unlock; the client could
be deleted by the drainer in between (same UAF pattern that was fixed
in PICloudServer::_readed). Keep the send inside the locked section:
sendData only takes mutex_send/prog_s_mutex downstream, so the lock
hold is bounded.
2026-08-23 18:55:00 +03:00
andrey cc8e8644f1 fix(picloud-dispatcher): do not close/delete clients under map_mutex — deadlock
cleanClients() (timer thread) called close()/stopAndWait() and
disconnectClient() (read thread) did the same while holding
map_mutex, while client read threads wait for the same lock in
registerServer/registerClient/disconnectClient — a guaranteed
deadlock (the -w watchdog aborts exactly this). disconnectClient
could also wait for its own read thread (self-wait in
waitThreadedReadFinished) and the destructor never stopped the timer
or drained the clients, leaving dangling lambda captures of this.

Restructure around a single drainer (the timer thread):
- cleanClients: under map_mutex only mark (move rmrf_* out, mark
  ping-timeout/orphaned clients); after the unlock close
  (stopAndWait) and delete the connections, then delete the servers
- disconnectClient: only mark under the lock, then request a
  non-blocking stop() on the affected connections; the drainer waits
  and deletes (no self-wait, nothing blocks while holding the lock)
- newConnection: start the read thread after releasing the lock
- ~DispatcherServer: stop watchdog/timer first, then close and delete
  all clients before the servers (raw-pointer order) and eth

The watchdog is now a PIThread member so the destructor can stop it;
setMaxConnections takes map_mutex like its readers.
2026-08-23 17:18:03 +03:00
andrey ddab6909b4 fix(picloud-dispatcher): guard CloudServer::stop() and last_ping with mutex_clients
stop() iterated clients while addClient()/removeClient() modified it
from other threads (reallocated vector iterators, data race). Copy the
list under mutex_clients and close the copy.

last_ping (PITimeMeasurer) was reset from the read thread
(dataReadedServer/pingReceived) without any lock while cleanClients
read it via lastPing() in the timer thread. Reset and read it under
mutex_clients (lock order map_mutex -> mutex_clients, consistent with
the registerClient path).
2026-08-23 17:17:53 +03:00
peri4 49713ddc57 PIThread now setup itself in thread func 2024-12-29 10:50:38 +03:00
peri4 92a87a0c64 picloud add "-w" option for watchdog 2024-10-15 15:04:39 +03:00
peri4 16a818c95e picloud hang fix try :`-( 2024-09-06 08:05:26 +03:00
peri4 1c7fc39b6c version 4.0.0_alpha
in almost all methods removed timeouts in milliseconds, replaced to PISystemTime
PITimer rewrite, remove internal impl, now only thread implementation, API similar to PIThread
PITimer API no longer pass void*
PIPeer, PIConnection improved stability on reinit and exit
PISystemTime new methods
pisd now exit without hanging
2024-07-30 14:18:02 +03:00
peri4 d46b5e008a try to fix cloud again 2024-06-01 22:27:39 +03:00
peri4 fb68a9f9fe another segv on cloud 2024-03-31 20:31:35 +03:00
peri4 c7c3852747 cloud! finally fixed bug! 2024-03-25 22:40:29 +03:00
peri4 c18d0c918e 4 2024-03-25 21:45:59 +03:00
peri4 9c4fd41eef 3 2024-03-25 21:37:05 +03:00
peri4 9173dc936d 2 2024-03-25 21:34:30 +03:00
peri4 77c8681b43 1 2024-03-25 21:31:41 +03:00
peri4 2db9440a38 fix cloud ... :-/ 2024-03-25 21:24:29 +03:00
peri4 0d585cfebf cloud fix ... (( 2024-03-25 21:17:05 +03:00
peri4 02a9bfb76f another try fix 2024-03-22 22:29:14 +03:00
peri4 ad7385c21f more couts 2024-03-22 21:40:04 +03:00
peri4 dd6d91ac1d cloud fixes ... 2024-03-18 10:45:57 +03:00
peri4 3fa5d9d9df cloud inspecting ... 2024-03-15 19:49:37 +03:00
peri4 2b738f6f43 more safety cloud_dispatcher 2024-03-10 21:22:05 +03:00
peri4 50bff12364 map and cloud fix, add cloud debug 2024-02-22 17:10:38 +03:00
peri4 2ac215c19e separate PIEthernet::Address to PINetworkAddress, typedef PIEthernet::Address to PINetworkAddress and mark as deprecated
PIValueTree new attributes for File and Dir
2022-12-19 14:29:18 +03:00
peri4 c2b8a8d6da code format 2022-12-14 14:13:52 +03:00
peri4 e9128771db version 3.6.0
another fixes in PIEthernet
remove PIThread::interrupt()
piwaitevent patches
2022-11-12 13:31:26 +03:00
Бычков Андрей cb59017ebb PICloud many important fixes 2022-11-11 16:18:05 +03:00
Бычков Андрей 8738043dce some PICloud and PIEthernet fixes 2022-11-09 17:04:13 +03:00
Бычков Андрей 897f03f3d0 some fixes for picloud, but still not working correctly 2022-11-08 14:43:52 +03:00
Бычков Андрей 93a1bf4f6d some unsuccessfull fixes for picloud 2022-11-07 17:32:10 +03:00
andrey 638f0e0181 PIIODevice remove init
picloud dispatcher fix
2022-10-23 19:22:36 +03:00
peri4 9438ab4e53 PIIODevice threaded read refactoring 2022-10-23 16:02:09 +03:00
peri4 8abc9777cc cmake refactoring 2022-08-08 15:41:01 +03:00
Бычков Андрей 170a713357 PIMap new functions
PIByteArray checksum crc
some doc fixes
2022-08-04 20:20:08 +03:00
peri4 f67e3030b9 move to PIIOTextStream 2022-05-13 13:24:09 +03:00
peri4 0ea1e2c856 support for git download of CMake project (standalone PIP build) 2022-05-08 22:22:48 +03:00
andrey f82b6c12ee cloud_dispatcher patch 2021-09-01 22:43:40 +03:00
andrey 00edfa4ef0 cloud data send optimize 2021-09-01 17:48:58 +03:00
andrey 35a3ce6402 picloudtcp.cpp revert some mutex 2021-09-01 10:56:11 +03:00
andrey 4c0530d89a picloud ping and fix big bugs 2021-08-19 18:13:05 +03:00
peri4 44b9c37391 PICloudClient now soft stop thread when closed
last cmake changes
2021-08-16 22:30:56 +03:00
andrey ee131921a0 add PIByteArray operator <, fix picloud 2021-08-12 20:22:43 +03:00
andrey f8818c8537 picloud patch 2021-08-12 19:50:17 +03:00
andrey ca09b9d14b piclouddispatcher patch 2021-08-06 10:49:14 +03:00
peri4 b6bce352a2 debian service 2021-08-03 05:58:04 +03:00
peri4 f3189472e6 picloud service 2021-07-26 12:22:58 +03:00
peri4 c91b54d325 picloud now can be configured from config
service fix
2021-07-26 11:49:52 +03:00
peri4 8f548920ac deploy fix 2021-07-25 10:42:46 +03:00
peri4 ca44846240 picloud deploy 2021-07-24 16:33:09 +03:00