Skip to content

Commit

Permalink
io_tls: Fix deadlock caused by blocked write.
Browse files Browse the repository at this point in the history
write(readpipe) can block in ssl_io_thread, leading to deadlock since
the list remains locked and no sessions can be registered or
unregistered.

Unblock readpipe[1] so that calls to write(readpipe...) don't block,
similar to how we unblock TLS reads from the client to avoid blocking
on read.
  • Loading branch information
InterLinked1 committed Oct 8, 2024
1 parent 4a854f9 commit b668d4c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion io/io_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ static int ssl_register_fd(SSL *ssl, int fd, int *rfd, int *wfd, int client)
*rfd = sfd->readpipe[0];
*wfd = sfd->writepipe[1];

bbs_unblock_fd(sfd->readpipe[1]); /* Make sure write(readpipe, ...) doesn't block */

SET_BITFIELD(sfd->client, client);

RWLIST_INSERT_HEAD(&sslfds, sfd, entry);
Expand Down Expand Up @@ -521,7 +523,8 @@ static void *ssl_io_thread(void *unused)
needcreate = 1;
continue;
}
wres = write(readpipe, buf, (size_t) ores);
/* This will not block, but we need to retry partial writes, as above with partial reads, hence bbs_write instead of write. */
wres = bbs_write(readpipe, buf, (size_t) ores);
if (wres != ores) {
bbs_error("Wanted to write %d bytes but wrote %ld?\n", ores, wres);
}
Expand Down

0 comments on commit b668d4c

Please sign in to comment.