Skip to content

Commit

Permalink
Correctly process invalid IO #332
Browse files Browse the repository at this point in the history
After the BLE Connection is established, a L2CAP socket will be added the GLib
Poll list via "g_io_add_watch()". But unfortunately the  "G_IO_NVAL" is missing
in the Condition Parameter of the "g_io_add_watch()".

Therefore if Disconnection happens (no matter it's triggered by the BluePy side,
or another side), namely the L2CAP Socket is closed by the Kernel Bluetooth Subsystem .
The missing condition "G_IO_NVAL" causes that the cleanup callback "channel_watcher"
will not be called. In this case, the GIO Event Source will not be removed from the GLib
Poll list properly. And the following infinite Loop happens and raises CPU Usage to 100%.

poll([{fd=0, events=POLLIN}, {fd=4, events=POLLIN}, {fd=5, events=0}], 3, -1) = 2 ([{fd=4, revents=POLLIN}, {fd=5, revents=POLLNVAL}])
// cleanup should happen, but not
poll([{fd=0, events=POLLIN}, {fd=4, events=POLLIN}, {fd=5, events=0}], 3, -1) = 1 ([{fd=5, revents=POLLNVAL}])
poll([{fd=0, events=POLLIN}, {fd=4, events=POLLIN}, {fd=5, events=0}], 3, -1) = 1 ([{fd=5, revents=POLLNVAL}])
  • Loading branch information
fsaris committed Apr 29, 2021
1 parent e6f7c7f commit 9679451
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bluepy/bluepy-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static void cmd_connect(int argcp, char **argvp)
g_error_free(gerr);
}
else
g_io_add_watch(iochannel, G_IO_HUP, channel_watcher, NULL);
g_io_add_watch(iochannel, G_IO_HUP | G_IO_NVAL, channel_watcher, NULL);
}

static void cmd_disconnect(int argcp, char **argvp)
Expand Down

0 comments on commit 9679451

Please sign in to comment.