Commit 766bd6f
committed
EC: sync clients also fire OnLost on read/write error so amuleweb / amulecmd exit cleanly
In sync mode (use_events=false on CECMuleSocket → amulecmd, amuleweb)
there's no pending async_read after the auth handshake, so the EOF
that fires HandleRead → PostLostEvent for async clients (amulegui)
never gets seen. SendRecvPacket detects the failure on its next
ReadSync (or WriteSync, eventually after keepalive teardown) and
returns NULL, but nothing notifies the EC layer — amuleweb continues
serving HTTP template shells forever with no live amuled data, no
error visible to the user, no exit. amulecmd sits at its prompt
with a dead socket and every command silently failing.
Fix: ReadSync / WriteSync, on a non-zero error_code, dispatch
OnLost(0) directly through the LibSocket wrapper (DispatchSyncLost
helper) — same dispatch path the asio reactor would take for async
clients, just synchronous since the sync-mode caller is already on
the main thread. From there:
* CECMuleSocket::OnLost(int) forwards through static_cast<CECSocket*>
to the EC-layer virtual.
* CRemoteConnect::OnLost: if m_notifier is set (amulegui), posts the
existing wxEVT_EC_CONNECTION event and the GUI handler flips the
UI. If NULL (amuleweb, amulecmd), prints "External Connection
lost — exiting" and calls _exit(1) so the supervisor (systemd /
shell / docker) decides whether to restart and reconnect.
Direct synchronous dispatch (rather than PostLostEvent + wxQueueEvent)
because amulecmd's main thread is in fgets reading stdin, not in
wxApp's event loop, so queued events would never be processed.
amuleweb's wxApp::OnRun is the main loop but it's not running while
the HTTP request handler is on the stack — direct dispatch from
the same sync-mode call site avoids both reactor and event-loop
coordination questions.
_exit instead of exit() because we're calling from the main thread
holding stacks the asio threads will tear down on shutdown; racing
static destructors against them risks the kind of UAF amule-project#748 was
about. The OS reaps fds / sockets on process exit anyway.
Live-verified on Linux VM:
* amulegui: TCP-level FIN observed, UI flips to "Connection failure"
within ~1s.
* amuleweb: First HTTP request after amuled killed returns with
stale template, then amuleweb exits before next request can be
served (curl gets connection refused).
* amulecmd: First "status" command after amuled killed prints
"External Connection lost — exiting" to stderr and exits with
code 1. User sees their shell prompt return.
Refs amule-project#757.1 parent 48a9850 commit 766bd6f
3 files changed
Lines changed: 55 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
719 | 722 | | |
720 | 723 | | |
721 | 724 | | |
| |||
724 | 727 | | |
725 | 728 | | |
726 | 729 | | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
727 | 733 | | |
728 | 734 | | |
729 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
730 | 756 | | |
731 | 757 | | |
732 | 758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
200 | 206 | | |
201 | 207 | | |
202 | 208 | | |
203 | | - | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
| 213 | + | |
206 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
207 | 230 | | |
208 | 231 | | |
209 | 232 | | |
| |||
0 commit comments