Commit bf6ce0f7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Improve the handling of h2 frame-reception when the connection closes.

Insist we get the frames we expect.
parent ec9c04d6
...@@ -269,8 +269,9 @@ client c1 { ...@@ -269,8 +269,9 @@ client c1 {
client c1 { client c1 {
stream 0 { stream 0 {
# SETTING unknown vlaue # SETTING unknown value
sendhex "000006 04 00 00000000 ffff00000000" sendhex "000006 04 00 00000000 ffff00000000"
rxsettings
txping txping
rxping rxping
} -run } -run
......
...@@ -177,27 +177,30 @@ get_bytes(const struct http *hp, char *buf, int n) ...@@ -177,27 +177,30 @@ get_bytes(const struct http *hp, char *buf, int n)
if (i < 0 && errno == EINTR) if (i < 0 && errno == EINTR)
continue; continue;
if (i == 0) if (i == 0)
vtc_log(hp->vl, hp->fatal, vtc_log(hp->vl, 3,
"HTTP2 rx timeout (fd:%d %u ms)", "HTTP2 rx timeout (fd:%d %u ms)",
hp->fd, hp->timeout); hp->fd, hp->timeout);
if (i < 0) if (i < 0)
vtc_log(hp->vl, hp->fatal, vtc_log(hp->vl, 3,
"HTTP2 rx failed (fd:%d poll: %s)", "HTTP2 rx failed (fd:%d poll: %s)",
hp->fd, strerror(errno)); hp->fd, strerror(errno));
assert(i > 0); if (i <= 0)
return (i);
i = read(hp->fd, buf, n); i = read(hp->fd, buf, n);
if (!(pfd[0].revents & POLLIN)) if (!(pfd[0].revents & POLLIN))
vtc_log(hp->vl, 4, vtc_log(hp->vl, 4,
"HTTP2 rx poll (fd:%d revents: %x n=%d, i=%d)", "HTTP2 rx poll (fd:%d revents: %x n=%d, i=%d)",
hp->fd, pfd[0].revents, n, i); hp->fd, pfd[0].revents, n, i);
if (i == 0) if (i == 0)
vtc_log(hp->vl, hp->fatal, vtc_log(hp->vl, 3,
"HTTP2 rx EOF (fd:%d read: %s)", "HTTP2 rx EOF (fd:%d read: %s)",
hp->fd, strerror(errno)); hp->fd, strerror(errno));
if (i < 0) if (i < 0)
vtc_log(hp->vl, hp->fatal, vtc_log(hp->vl, 3,
"HTTP2 rx failed (fd:%d read: %s)", "HTTP2 rx failed (fd:%d read: %s)",
hp->fd, strerror(errno)); hp->fd, strerror(errno));
if (i <= 0)
return (i);
n -= i; n -= i;
} }
return (1); return (1);
...@@ -729,7 +732,12 @@ receive_frame(void *priv) ...@@ -729,7 +732,12 @@ receive_frame(void *priv)
AZ(pthread_mutex_unlock(&hp->mtx)); AZ(pthread_mutex_unlock(&hp->mtx));
if (!get_bytes(hp, hdr, 9)) { if (!get_bytes(hp, hdr, 9)) {
vtc_log(hp->vl, 1, "could not get header"); AZ(pthread_mutex_lock(&hp->mtx));
VTAILQ_FOREACH(s, &hp->streams, list)
AZ(pthread_cond_signal(&s->cond));
AZ(pthread_mutex_unlock(&hp->mtx));
vtc_log(hp->vl, hp->fatal,
"could not get frame header");
return (NULL); return (NULL);
} }
ALLOC_OBJ(f, FRAME_MAGIC); ALLOC_OBJ(f, FRAME_MAGIC);
...@@ -747,7 +755,15 @@ receive_frame(void *priv) ...@@ -747,7 +755,15 @@ receive_frame(void *priv)
f->data = malloc(f->size + 1L); f->data = malloc(f->size + 1L);
AN(f->data); AN(f->data);
f->data[f->size] = '\0'; f->data[f->size] = '\0';
AN(get_bytes(hp, f->data, f->size)); if (get_bytes(hp, f->data, f->size) <= 0) {
AZ(pthread_mutex_lock(&hp->mtx));
VTAILQ_FOREACH(s, &hp->streams, list)
AZ(pthread_cond_signal(&s->cond));
AZ(pthread_mutex_unlock(&hp->mtx));
vtc_log(hp->vl, hp->fatal,
"could not get frame body");
return (NULL);
}
} }
/* is the corresponding stream waiting? */ /* is the corresponding stream waiting? */
...@@ -2331,12 +2347,13 @@ cmd_rxpush(CMD_ARGS) ...@@ -2331,12 +2347,13 @@ cmd_rxpush(CMD_ARGS)
(void)cmd; \ (void)cmd; \
(void)av; \ (void)av; \
CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC); \ CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC); \
if ((s->frame = rxstuff(s))) \ s->frame = rxstuff(s); \
return; \ if (s->frame != NULL && s->frame->type != TYPE_ ## upctype) \
if (s->frame->type != TYPE_ ## upctype) \ vtc_fatal(vl, \
vtc_fatal(vl, "Received frame of type %d " \ "Wrong frame type %s (%d) wanted %s", \
"is invalid for %s", \ s->frame->type < TYPE_MAX ? \
s->frame->type, "rx" #lctype); \ h2_types[s->frame->type] : "?", \
s->frame->type, #upctype); \
} }
/* SECTION: stream.spec.prio_rxprio rxprio /* SECTION: stream.spec.prio_rxprio rxprio
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment