View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002957 | CCdciel | General | public | 26-10-06 23:16 | 26-10-06 23:16 |
| Reporter | Jan Dubovsky | Assigned To | |||
| Priority | normal | Severity | major | Reproducibility | N/A |
| Status | new | Resolution | open | ||
| Summary | 0002957: Race condition on the PHD2 TCP socket in the internal autoguider client | ||||
| Description | `T_autoguider_phd` (src/cu_autoguider_phd.pas) is itself a `TThread`. `Execute` (~line 115-157) runs the receive loop and, in its `finally` block, calls `tcpclient.Disconnect` and `tcpclient.Free` once the thread terminates. `Send` (~line 159-172), which is called from the main thread (via Guide/Pause/Dither/GetLockPosition), only guards access with a non-atomic check: `(not terminated) and (tcpclient <> nil)`, then calls `tcpclient.Sock.SendString(...)`. There is no critical section protecting `tcpclient` between the two methods. If `Terminate` fires concurrently — e.g. the thread notices a connection error, or the user disconnects while `WaitBusy`/`WaitGuiding` is pumping `Application.ProcessMessages` and re-enters — `Execute`'s `finally` block can free `tcpclient` in the small window right after `Send`'s check passed, resulting in an access to freed memory. | ||||
| Steps To Reproduce | Hard to reproduce deterministically; most likely when PHD2 is disconnected or its connection drops while actively guiding or dithering. Observed as an intermittent crash / access violation around PHD2 disconnect. | ||||
| Additional Information | ### Suggested fix Protect `tcpclient` with a critical section (or an atomic reference/interlocked flag) shared between `Execute`'s teardown and `Send`, so `Send` cannot run concurrently with `tcpclient.Free`. | ||||
| Tags | crash | ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 26-10-06 23:16 | Jan Dubovsky | New Issue | |
| 26-10-06 23:16 | Jan Dubovsky | Tag Attached: crash |