Skip to content

Commit

Permalink
Merge pull request #241 from openziti/tlsuv-stream-fail-pending-writes
Browse files Browse the repository at this point in the history
when write fails also fail all pending write requests
  • Loading branch information
ekoby authored Oct 1, 2024
2 parents 53a2cf0 + 72e0000 commit de55983
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/tlsuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,9 @@ static void fail_pending_reqs(tlsuv_stream_t *clt, int err) {

static void process_outbound(tlsuv_stream_t *clt) {
tlsuv_write_t *req;
ssize_t ret;

for (;;) {
if (TAILQ_EMPTY(&clt->queue)) {
return;
}
ssize_t ret = 0;

while (!TAILQ_EMPTY(&clt->queue)) {
req = TAILQ_FIRST(&clt->queue);
ret = write_req(clt, &req->buf);
if (ret > 0) {
Expand All @@ -336,6 +332,7 @@ static void process_outbound(tlsuv_stream_t *clt) {
req->wr->cb(req->wr, 0);
}
tlsuv__free(req);
req = NULL;
}
continue;
}
Expand All @@ -344,15 +341,22 @@ static void process_outbound(tlsuv_stream_t *clt) {
return;
}

UM_LOG(WARN, "failed to write: %d/%s", (int)ret, uv_strerror(ret));
TAILQ_REMOVE(&clt->queue, req, _next);
clt->queue_len -= 1;
if (req->wr->cb) {
req->wr->cb(req->wr, (int)ret);
}
break;
}

// write failed so fail all queued requests
if (ret < 0) {
UM_LOG(WARN, "failed to write: %d/%s", (int)ret, uv_strerror(ret));
while (!TAILQ_EMPTY(&clt->queue)) {
req = TAILQ_FIRST(&clt->queue);
TAILQ_REMOVE(&clt->queue, req, _next);
clt->queue_len -= 1;
if (req->wr->cb) {
req->wr->cb(req->wr, (int) ret);
}
tlsuv__free(req);
}
}
}

static void process_inbound(tlsuv_stream_t *clt) {
Expand Down

0 comments on commit de55983

Please sign in to comment.