Skip to content

Commit

Permalink
network-stack: Fix deadlock in perform_on_lwip_thread()
Browse files Browse the repository at this point in the history
Where in the case of already being on the lwIP thread, we would enqueue
the request and then perform whichever is the oldest pending request. So
when there was already one or more requests pending, we would perform
that request instead. Then next we would join() our request, assuming it
had completed, and end up deadlocking the lwIP thread.

Kudos to @mrmacete for reporting and helping track this one down.

Co-authored-by: Håvard Sørbø <[email protected]>
  • Loading branch information
oleavr and hsorbo committed Sep 6, 2024
1 parent 5606120 commit 2f168f6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/fruity/network-stack.vala
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ namespace Frida.Fruity {
internal LWIP.ErrorCode perform_on_lwip_thread (owned WorkFunc work) {
var req = new Request ((owned) work);

lock (requests)
requests.offer (req);

if (Thread.self<bool> () != lwip_thread)
if (Thread.self<bool> () == lwip_thread) {
perform_request (req);
} else {
lock (requests)
requests.offer (req);
LWIP.Runtime.schedule (perform_next_request);
else
perform_next_request ();
}

return req.join ();
}
Expand All @@ -307,6 +307,10 @@ namespace Frida.Fruity {
lock (requests)
req = requests.poll ();

perform_request (res);
}

private void perform_request (Request req) {
LWIP.ErrorCode err = req.work ();
req.complete (err);
}
Expand Down

0 comments on commit 2f168f6

Please sign in to comment.