|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <assert.h>
|
|
Packit |
90a5c9 |
#include <stddef.h>
|
|
Packit |
90a5c9 |
#include <apr_thread_cond.h>
|
|
Packit |
90a5c9 |
#include <apr_base64.h>
|
|
Packit |
90a5c9 |
#include <apr_strings.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <ap_mpm.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <httpd.h>
|
|
Packit |
90a5c9 |
#include <http_core.h>
|
|
Packit |
90a5c9 |
#include <http_config.h>
|
|
Packit |
90a5c9 |
#include <http_log.h>
|
|
Packit |
90a5c9 |
#include <scoreboard.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <mpm_common.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "h2_private.h"
|
|
Packit |
90a5c9 |
#include "h2.h"
|
|
Packit |
90a5c9 |
#include "h2_bucket_beam.h"
|
|
Packit |
90a5c9 |
#include "h2_bucket_eos.h"
|
|
Packit |
90a5c9 |
#include "h2_config.h"
|
|
Packit |
90a5c9 |
#include "h2_ctx.h"
|
|
Packit |
90a5c9 |
#include "h2_filter.h"
|
|
Packit |
90a5c9 |
#include "h2_h2.h"
|
|
Packit |
90a5c9 |
#include "h2_mplx.h"
|
|
Packit |
90a5c9 |
#include "h2_push.h"
|
|
Packit |
90a5c9 |
#include "h2_request.h"
|
|
Packit |
90a5c9 |
#include "h2_headers.h"
|
|
Packit |
90a5c9 |
#include "h2_stream.h"
|
|
Packit |
90a5c9 |
#include "h2_task.h"
|
|
Packit |
90a5c9 |
#include "h2_session.h"
|
|
Packit |
90a5c9 |
#include "h2_util.h"
|
|
Packit |
90a5c9 |
#include "h2_version.h"
|
|
Packit |
90a5c9 |
#include "h2_workers.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t dispatch_master(h2_session *session);
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_read(h2_session *session, int block);
|
|
Packit |
90a5c9 |
static void transit(h2_session *session, const char *action,
|
|
Packit |
90a5c9 |
h2_session_state nstate);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void on_stream_state_enter(void *ctx, h2_stream *stream);
|
|
Packit |
90a5c9 |
static void on_stream_state_event(void *ctx, h2_stream *stream, h2_stream_event_t ev);
|
|
Packit |
90a5c9 |
static void on_stream_event(void *ctx, h2_stream *stream, h2_stream_event_t ev);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int h2_session_status_from_apr_status(apr_status_t rv)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (rv == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return NGHTTP2_NO_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_EAGAIN(rv)) {
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_WOULDBLOCK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_EOF(rv)) {
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_EOF;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_PROTO;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_stream *h2_session_stream_get(h2_session *session, int stream_id)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return nghttp2_session_get_stream_user_data(session->ngh2, stream_id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void dispatch_event(h2_session *session, h2_session_event_t ev,
|
|
Packit |
90a5c9 |
int err, const char *msg);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void h2_session_event(h2_session *session, h2_session_event_t ev,
|
|
Packit |
90a5c9 |
int err, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
dispatch_event(session, ev, err, msg);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int rst_unprocessed_stream(h2_stream *stream, void *ctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int unprocessed = (!h2_stream_was_closed(stream)
|
|
Packit |
90a5c9 |
&& (H2_STREAM_CLIENT_INITIATED(stream->id)?
|
|
Packit |
90a5c9 |
(!stream->session->local.accepting
|
|
Packit |
90a5c9 |
&& stream->id > stream->session->local.accepted_max)
|
|
Packit |
90a5c9 |
:
|
|
Packit |
90a5c9 |
(!stream->session->remote.accepting
|
|
Packit |
90a5c9 |
&& stream->id > stream->session->remote.accepted_max))
|
|
Packit |
90a5c9 |
);
|
|
Packit |
90a5c9 |
if (unprocessed) {
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, H2_ERR_NO_ERROR);
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void cleanup_unprocessed_streams(h2_session *session)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_mplx_stream_do(session->mplx, rst_unprocessed_stream, session);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static h2_stream *h2_session_open_stream(h2_session *session, int stream_id,
|
|
Packit |
90a5c9 |
int initiated_on)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_stream * stream;
|
|
Packit |
90a5c9 |
apr_pool_t *stream_pool;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_create(&stream_pool, session->pool);
|
|
Packit |
90a5c9 |
apr_pool_tag(stream_pool, "h2_stream");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
stream = h2_stream_create(stream_id, stream_pool, session,
|
|
Packit |
90a5c9 |
session->monitor, initiated_on);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
nghttp2_session_set_stream_user_data(session->ngh2, stream_id, stream);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return stream;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Determine the importance of streams when scheduling tasks.
|
|
Packit |
90a5c9 |
* - if both stream depend on the same one, compare weights
|
|
Packit |
90a5c9 |
* - if one stream is closer to the root, prioritize that one
|
|
Packit |
90a5c9 |
* - if both are on the same level, use the weight of their root
|
|
Packit |
90a5c9 |
* level ancestors
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int spri_cmp(int sid1, nghttp2_stream *s1,
|
|
Packit |
90a5c9 |
int sid2, nghttp2_stream *s2, h2_session *session)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
nghttp2_stream *p1, *p2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
p1 = nghttp2_stream_get_parent(s1);
|
|
Packit |
90a5c9 |
p2 = nghttp2_stream_get_parent(s2);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (p1 == p2) {
|
|
Packit |
90a5c9 |
int32_t w1, w2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
w1 = nghttp2_stream_get_weight(s1);
|
|
Packit |
90a5c9 |
w2 = nghttp2_stream_get_weight(s2);
|
|
Packit |
90a5c9 |
return w2 - w1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!p1) {
|
|
Packit |
90a5c9 |
/* stream 1 closer to root */
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!p2) {
|
|
Packit |
90a5c9 |
/* stream 2 closer to root */
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return spri_cmp(sid1, p1, sid2, p2, session);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int stream_pri_cmp(int sid1, int sid2, void *ctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = ctx;
|
|
Packit |
90a5c9 |
nghttp2_stream *s1, *s2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s1 = nghttp2_session_find_stream(session->ngh2, sid1);
|
|
Packit |
90a5c9 |
s2 = nghttp2_session_find_stream(session->ngh2, sid2);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (s1 == s2) {
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!s1) {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!s2) {
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return spri_cmp(sid1, s1, sid2, s2, session);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Callback when nghttp2 wants to send bytes back to the client.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static ssize_t send_cb(nghttp2_session *ngh2,
|
|
Packit |
90a5c9 |
const uint8_t *data, size_t length,
|
|
Packit |
90a5c9 |
int flags, void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
(void)ngh2;
|
|
Packit |
90a5c9 |
(void)flags;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_conn_io_write(&session->io, (const char *)data, length);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return length;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_EAGAIN(status)) {
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_WOULDBLOCK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c, APLOGNO(03062)
|
|
Packit |
90a5c9 |
"h2_session: send error");
|
|
Packit |
90a5c9 |
return h2_session_status_from_apr_status(status);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_invalid_frame_recv_cb(nghttp2_session *ngh2,
|
|
Packit |
90a5c9 |
const nghttp2_frame *frame,
|
|
Packit |
90a5c9 |
int error, void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
(void)ngh2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APLOGcdebug(session->c)) {
|
|
Packit |
90a5c9 |
char buffer[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_util_frame_print(frame, buffer, sizeof(buffer)/sizeof(buffer[0]));
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03063), session,
|
|
Packit |
90a5c9 |
"recv invalid FRAME[%s], frames=%ld/%ld (r/s)"),
|
|
Packit |
90a5c9 |
buffer, (long)session->frames_received,
|
|
Packit |
90a5c9 |
(long)session->frames_sent);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_data_chunk_recv_cb(nghttp2_session *ngh2, uint8_t flags,
|
|
Packit |
90a5c9 |
int32_t stream_id,
|
|
Packit |
90a5c9 |
const uint8_t *data, size_t len, void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
apr_status_t status = APR_EINVAL;
|
|
Packit |
90a5c9 |
h2_stream * stream;
|
|
Packit |
90a5c9 |
int rv = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, stream_id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
status = h2_stream_recv_DATA(stream, flags, data, len);
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_STREAM_CHANGE, 0, "stream data rcvd");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(03064)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): on_data_chunk for unknown stream",
|
|
Packit |
90a5c9 |
session->id, (int)stream_id);
|
|
Packit |
90a5c9 |
rv = NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* count this as consumed explicitly as no one will read it */
|
|
Packit |
90a5c9 |
nghttp2_session_consume(session->ngh2, stream_id, len);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_stream_close_cb(nghttp2_session *ngh2, int32_t stream_id,
|
|
Packit |
90a5c9 |
uint32_t error_code, void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
(void)ngh2;
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, stream_id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
if (error_code) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03065), stream,
|
|
Packit |
90a5c9 |
"closing with err=%d %s"),
|
|
Packit |
90a5c9 |
(int)error_code, h2_h2_err_description(error_code));
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, error_code);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_begin_headers_cb(nghttp2_session *ngh2,
|
|
Packit |
90a5c9 |
const nghttp2_frame *frame, void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
h2_stream *s;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* We may see HEADERs at the start of a stream or after all DATA
|
|
Packit |
90a5c9 |
* streams to carry trailers. */
|
|
Packit |
90a5c9 |
(void)ngh2;
|
|
Packit |
90a5c9 |
s = h2_session_stream_get(session, frame->hd.stream_id);
|
|
Packit |
90a5c9 |
if (s) {
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
s = h2_session_open_stream(userp, frame->hd.stream_id, 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return s? 0 : NGHTTP2_ERR_START_STREAM_NOT_ALLOWED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_header_cb(nghttp2_session *ngh2, const nghttp2_frame *frame,
|
|
Packit |
90a5c9 |
const uint8_t *name, size_t namelen,
|
|
Packit |
90a5c9 |
const uint8_t *value, size_t valuelen,
|
|
Packit |
90a5c9 |
uint8_t flags,
|
|
Packit |
90a5c9 |
void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
h2_stream * stream;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
(void)flags;
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, frame->hd.stream_id);
|
|
Packit |
90a5c9 |
if (!stream) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(02920)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): on_header unknown stream",
|
|
Packit |
90a5c9 |
session->id, (int)frame->hd.stream_id);
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_stream_add_header(stream, (const char *)name, namelen,
|
|
Packit |
90a5c9 |
(const char *)value, valuelen);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS && !h2_stream_is_ready(stream)) {
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* nghttp2 session has received a complete frame. Most are used by nghttp2
|
|
Packit |
90a5c9 |
* for processing of internal state. Some, like HEADER and DATA frames,
|
|
Packit |
90a5c9 |
* we need to act on.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int on_frame_recv_cb(nghttp2_session *ng2s,
|
|
Packit |
90a5c9 |
const nghttp2_frame *frame,
|
|
Packit |
90a5c9 |
void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
apr_status_t rv = APR_SUCCESS;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APLOGcdebug(session->c)) {
|
|
Packit |
90a5c9 |
char buffer[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_util_frame_print(frame, buffer, sizeof(buffer)/sizeof(buffer[0]));
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03066), session,
|
|
Packit |
90a5c9 |
"recv FRAME[%s], frames=%ld/%ld (r/s)"),
|
|
Packit |
90a5c9 |
buffer, (long)session->frames_received,
|
|
Packit |
90a5c9 |
(long)session->frames_sent);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
++session->frames_received;
|
|
Packit |
90a5c9 |
switch (frame->hd.type) {
|
|
Packit |
90a5c9 |
case NGHTTP2_HEADERS:
|
|
Packit |
90a5c9 |
/* This can be HEADERS for a new stream, defining the request,
|
|
Packit |
90a5c9 |
* or HEADER may come after DATA at the end of a stream as in
|
|
Packit |
90a5c9 |
* trailers */
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, frame->hd.stream_id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
rv = h2_stream_recv_frame(stream, NGHTTP2_HEADERS, frame->hd.flags,
|
|
Packit |
90a5c9 |
frame->hd.length + H2_FRAME_HDR_LEN);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case NGHTTP2_DATA:
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, frame->hd.stream_id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(02923), stream,
|
|
Packit |
90a5c9 |
"DATA, len=%ld, flags=%d"),
|
|
Packit |
90a5c9 |
(long)frame->hd.length, frame->hd.flags);
|
|
Packit |
90a5c9 |
rv = h2_stream_recv_frame(stream, NGHTTP2_DATA, frame->hd.flags,
|
|
Packit |
90a5c9 |
frame->hd.length + H2_FRAME_HDR_LEN);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case NGHTTP2_PRIORITY:
|
|
Packit |
90a5c9 |
session->reprioritize = 1;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): PRIORITY frame "
|
|
Packit |
90a5c9 |
" weight=%d, dependsOn=%d, exclusive=%d",
|
|
Packit |
90a5c9 |
session->id, (int)frame->hd.stream_id,
|
|
Packit |
90a5c9 |
frame->priority.pri_spec.weight,
|
|
Packit |
90a5c9 |
frame->priority.pri_spec.stream_id,
|
|
Packit |
90a5c9 |
frame->priority.pri_spec.exclusive);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case NGHTTP2_WINDOW_UPDATE:
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): WINDOW_UPDATE incr=%d",
|
|
Packit |
90a5c9 |
session->id, (int)frame->hd.stream_id,
|
|
Packit |
90a5c9 |
frame->window_update.window_size_increment);
|
|
Packit |
90a5c9 |
if (nghttp2_session_want_write(session->ngh2)) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_FRAME_RCVD, 0, "window update");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case NGHTTP2_RST_STREAM:
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(03067)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): RST_STREAM by client, errror=%d",
|
|
Packit |
90a5c9 |
session->id, (int)frame->hd.stream_id,
|
|
Packit |
90a5c9 |
(int)frame->rst_stream.error_code);
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, frame->hd.stream_id);
|
|
Packit |
90a5c9 |
if (stream && stream->initiated_on) {
|
|
Packit |
90a5c9 |
++session->pushes_reset;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
++session->streams_reset;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case NGHTTP2_GOAWAY:
|
|
Packit |
90a5c9 |
if (frame->goaway.error_code == 0
|
|
Packit |
90a5c9 |
&& frame->goaway.last_stream_id == ((1u << 31) - 1)) {
|
|
Packit |
90a5c9 |
/* shutdown notice. Should not come from a client... */
|
|
Packit |
90a5c9 |
session->remote.accepting = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
session->remote.accepted_max = frame->goaway.last_stream_id;
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_REMOTE_GOAWAY,
|
|
Packit |
90a5c9 |
frame->goaway.error_code, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case NGHTTP2_SETTINGS:
|
|
Packit |
90a5c9 |
if (APLOGctrace2(session->c)) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "SETTINGS, len=%ld"), (long)frame->hd.length);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
if (APLOGctrace2(session->c)) {
|
|
Packit |
90a5c9 |
char buffer[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_util_frame_print(frame, buffer,
|
|
Packit |
90a5c9 |
sizeof(buffer)/sizeof(buffer[0]));
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "on_frame_rcv %s"), buffer);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (session->state == H2_SESSION_ST_IDLE) {
|
|
Packit |
90a5c9 |
/* We received a frame, but session is in state IDLE. That means the frame
|
|
Packit |
90a5c9 |
* did not really progress any of the (possibly) open streams. It was a meta
|
|
Packit |
90a5c9 |
* frame, e.g. SETTINGS/WINDOW_UPDATE/unknown/etc.
|
|
Packit |
90a5c9 |
* Remember: IDLE means we cannot send because either there are no streams open or
|
|
Packit |
90a5c9 |
* all open streams are blocked on exhausted WINDOWs for outgoing data.
|
|
Packit |
90a5c9 |
* The more frames we receive that do not change this, the less interested we
|
|
Packit |
90a5c9 |
* become in serving this connection. This is expressed in increasing "idle_delays".
|
|
Packit |
90a5c9 |
* Eventually, the connection will timeout and we'll close it. */
|
|
Packit |
90a5c9 |
session->idle_frames = H2MIN(session->idle_frames + 1, session->frames_received);
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "session has %ld idle frames"),
|
|
Packit |
90a5c9 |
(long)session->idle_frames);
|
|
Packit |
90a5c9 |
if (session->idle_frames > 10) {
|
|
Packit |
90a5c9 |
apr_size_t busy_frames = H2MAX(session->frames_received - session->idle_frames, 1);
|
|
Packit |
90a5c9 |
int idle_ratio = (int)(session->idle_frames / busy_frames);
|
|
Packit |
90a5c9 |
if (idle_ratio > 100) {
|
|
Packit |
90a5c9 |
session->idle_delay = apr_time_from_msec(H2MIN(1000, idle_ratio));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (idle_ratio > 10) {
|
|
Packit |
90a5c9 |
session->idle_delay = apr_time_from_msec(10);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (idle_ratio > 1) {
|
|
Packit |
90a5c9 |
session->idle_delay = apr_time_from_msec(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
session->idle_delay = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APR_SUCCESS != rv) return NGHTTP2_ERR_PROTO;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int h2_session_continue_data(h2_session *session) {
|
|
Packit |
90a5c9 |
if (h2_mplx_has_master_events(session->mplx)) {
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (h2_conn_io_needs_flush(&session->io)) {
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char immortal_zeros[H2_MAX_PADLEN];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_send_data_cb(nghttp2_session *ngh2,
|
|
Packit |
90a5c9 |
nghttp2_frame *frame,
|
|
Packit |
90a5c9 |
const uint8_t *framehd,
|
|
Packit |
90a5c9 |
size_t length,
|
|
Packit |
90a5c9 |
nghttp2_data_source *source,
|
|
Packit |
90a5c9 |
void *userp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = APR_SUCCESS;
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)userp;
|
|
Packit |
90a5c9 |
int stream_id = (int)frame->hd.stream_id;
|
|
Packit |
90a5c9 |
unsigned char padlen;
|
|
Packit |
90a5c9 |
int eos;
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
apr_bucket *b;
|
|
Packit |
90a5c9 |
apr_off_t len = length;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
(void)ngh2;
|
|
Packit |
90a5c9 |
(void)source;
|
|
Packit |
90a5c9 |
if (!h2_session_continue_data(session)) {
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_WOULDBLOCK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (frame->data.padlen > H2_MAX_PADLEN) {
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_PROTO;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
padlen = (unsigned char)frame->data.padlen;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, stream_id);
|
|
Packit |
90a5c9 |
if (!stream) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_NOTFOUND, session->c,
|
|
Packit |
90a5c9 |
APLOGNO(02924)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): send_data, stream not found",
|
|
Packit |
90a5c9 |
session->id, (int)stream_id);
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "send_data_cb for %ld bytes"),
|
|
Packit |
90a5c9 |
(long)length);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_conn_io_write(&session->io, (const char *)framehd, 9);
|
|
Packit |
90a5c9 |
if (padlen && status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
status = h2_conn_io_write(&session->io, (const char *)&padlen, 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "writing frame header"));
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_stream_read_to(stream, session->bbtmp, &len, &eos;;
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "send_data_cb, reading stream"));
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(session->bbtmp);
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (len != length) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "send_data_cb, wanted %ld bytes, "
|
|
Packit |
90a5c9 |
"got %ld from stream"), (long)length, (long)len);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(session->bbtmp);
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (padlen) {
|
|
Packit |
90a5c9 |
b = apr_bucket_immortal_create(immortal_zeros, padlen,
|
|
Packit |
90a5c9 |
session->c->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(session->bbtmp, b);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_conn_io_pass(&session->io, session->bbtmp);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(session->bbtmp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
stream->out_data_frames++;
|
|
Packit |
90a5c9 |
stream->out_data_octets += length;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(02925), stream, "failed send_data_cb"));
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int on_frame_send_cb(nghttp2_session *ngh2,
|
|
Packit |
90a5c9 |
const nghttp2_frame *frame,
|
|
Packit |
90a5c9 |
void *user_data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = user_data;
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
int stream_id = frame->hd.stream_id;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
++session->frames_sent;
|
|
Packit |
90a5c9 |
switch (frame->hd.type) {
|
|
Packit |
90a5c9 |
case NGHTTP2_PUSH_PROMISE:
|
|
Packit |
90a5c9 |
/* PUSH_PROMISE we report on the promised stream */
|
|
Packit |
90a5c9 |
stream_id = frame->push_promise.promised_stream_id;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APLOGcdebug(session->c)) {
|
|
Packit |
90a5c9 |
char buffer[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_util_frame_print(frame, buffer, sizeof(buffer)/sizeof(buffer[0]));
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03068), session,
|
|
Packit |
90a5c9 |
"sent FRAME[%s], frames=%ld/%ld (r/s)"),
|
|
Packit |
90a5c9 |
buffer, (long)session->frames_received,
|
|
Packit |
90a5c9 |
(long)session->frames_sent);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, stream_id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
h2_stream_send_frame(stream, frame->hd.type, frame->hd.flags,
|
|
Packit |
90a5c9 |
frame->hd.length + H2_FRAME_HDR_LEN);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef H2_NG2_INVALID_HEADER_CB
|
|
Packit |
90a5c9 |
static int on_invalid_header_cb(nghttp2_session *ngh2,
|
|
Packit |
90a5c9 |
const nghttp2_frame *frame,
|
|
Packit |
90a5c9 |
const uint8_t *name, size_t namelen,
|
|
Packit |
90a5c9 |
const uint8_t *value, size_t valuelen,
|
|
Packit |
90a5c9 |
uint8_t flags, void *user_data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = user_data;
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APLOGcdebug(session->c)) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(03456)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): invalid header '%s: %s'",
|
|
Packit |
90a5c9 |
session->id, (int)frame->hd.stream_id,
|
|
Packit |
90a5c9 |
apr_pstrndup(session->pool, (const char *)name, namelen),
|
|
Packit |
90a5c9 |
apr_pstrndup(session->pool, (const char *)value, valuelen));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, frame->hd.stream_id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, NGHTTP2_PROTOCOL_ERROR);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define NGH2_SET_CALLBACK(callbacks, name, fn)\
|
|
Packit |
90a5c9 |
nghttp2_session_callbacks_set_##name##_callback(callbacks, fn)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t init_callbacks(conn_rec *c, nghttp2_session_callbacks **pcb)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int rv = nghttp2_session_callbacks_new(pcb);
|
|
Packit |
90a5c9 |
if (rv != 0) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
|
|
Packit |
90a5c9 |
APLOGNO(02926) "nghttp2_session_callbacks_new: %s",
|
|
Packit |
90a5c9 |
nghttp2_strerror(rv));
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, send, send_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_frame_recv, on_frame_recv_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_invalid_frame_recv, on_invalid_frame_recv_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_data_chunk_recv, on_data_chunk_recv_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_stream_close, on_stream_close_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_begin_headers, on_begin_headers_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_header, on_header_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, send_data, on_send_data_cb);
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_frame_send, on_frame_send_cb);
|
|
Packit |
90a5c9 |
#ifdef H2_NG2_INVALID_HEADER_CB
|
|
Packit |
90a5c9 |
NGH2_SET_CALLBACK(*pcb, on_invalid_header, on_invalid_header_cb);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_shutdown_notice(h2_session *session)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_assert(session);
|
|
Packit |
90a5c9 |
if (!session->local.accepting) {
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
nghttp2_submit_shutdown_notice(session->ngh2);
|
|
Packit |
90a5c9 |
session->local.accepting = 0;
|
|
Packit |
90a5c9 |
status = nghttp2_session_send(session->ngh2);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
status = h2_conn_io_flush(&session->io);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03457), session, "sent shutdown notice"));
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_shutdown(h2_session *session, int error,
|
|
Packit |
90a5c9 |
const char *msg, int force_close)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = APR_SUCCESS;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_assert(session);
|
|
Packit |
90a5c9 |
if (session->local.shutdown) {
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!msg && error) {
|
|
Packit |
90a5c9 |
msg = nghttp2_strerror(error);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (error || force_close) {
|
|
Packit |
90a5c9 |
/* not a graceful shutdown, we want to leave...
|
|
Packit |
90a5c9 |
* Do not start further streams that are waiting to be scheduled.
|
|
Packit |
90a5c9 |
* Find out the max stream id that we habe been processed or
|
|
Packit |
90a5c9 |
* are still actively working on.
|
|
Packit |
90a5c9 |
* Remove all streams greater than this number without submitting
|
|
Packit |
90a5c9 |
* a RST_STREAM frame, since that should be clear from the GOAWAY
|
|
Packit |
90a5c9 |
* we send. */
|
|
Packit |
90a5c9 |
session->local.accepted_max = h2_mplx_shutdown(session->mplx);
|
|
Packit |
90a5c9 |
session->local.error = error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* graceful shutdown. we will continue processing all streams
|
|
Packit |
90a5c9 |
* we have, but no longer accept new ones. Report the max stream
|
|
Packit |
90a5c9 |
* we have received and discard all new ones. */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->local.accepting = 0;
|
|
Packit |
90a5c9 |
session->local.shutdown = 1;
|
|
Packit |
90a5c9 |
if (!session->c->aborted) {
|
|
Packit |
90a5c9 |
nghttp2_submit_goaway(session->ngh2, NGHTTP2_FLAG_NONE,
|
|
Packit |
90a5c9 |
session->local.accepted_max,
|
|
Packit |
90a5c9 |
error, (uint8_t*)msg, msg? strlen(msg):0);
|
|
Packit |
90a5c9 |
status = nghttp2_session_send(session->ngh2);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
status = h2_conn_io_flush(&session->io);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03069), session,
|
|
Packit |
90a5c9 |
"sent GOAWAY, err=%d, msg=%s"), error, msg? msg : "");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_LOCAL_GOAWAY, error, msg);
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t session_cleanup(h2_session *session, const char *trigger)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
conn_rec *c = session->c;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "pool_cleanup"));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (session->state != H2_SESSION_ST_DONE
|
|
Packit |
90a5c9 |
&& session->state != H2_SESSION_ST_INIT) {
|
|
Packit |
90a5c9 |
/* Not good. The connection is being torn down and we have
|
|
Packit |
90a5c9 |
* not sent a goaway. This is considered a protocol error and
|
|
Packit |
90a5c9 |
* the client has to assume that any streams "in flight" may have
|
|
Packit |
90a5c9 |
* been processed and are not safe to retry.
|
|
Packit |
90a5c9 |
* As clients with idle connection may only learn about a closed
|
|
Packit |
90a5c9 |
* connection when sending the next request, this has the effect
|
|
Packit |
90a5c9 |
* that at least this one request will fail.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_WARNING, 0, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03199), session,
|
|
Packit |
90a5c9 |
"connection disappeared without proper "
|
|
Packit |
90a5c9 |
"goodbye, clients will be confused, should not happen"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
transit(session, trigger, H2_SESSION_ST_CLEANUP);
|
|
Packit |
90a5c9 |
h2_mplx_release_and_join(session->mplx, session->iowait);
|
|
Packit |
90a5c9 |
session->mplx = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_assert(session->ngh2);
|
|
Packit |
90a5c9 |
nghttp2_session_del(session->ngh2);
|
|
Packit |
90a5c9 |
session->ngh2 = NULL;
|
|
Packit |
90a5c9 |
h2_ctx_clear(c);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t session_pool_cleanup(void *data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
conn_rec *c = data;
|
|
Packit |
90a5c9 |
h2_session *session;
|
|
Packit |
90a5c9 |
h2_ctx *ctx = h2_ctx_get(c, 0);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ctx && (session = h2_ctx_session_get(ctx))) {
|
|
Packit |
90a5c9 |
/* if the session is still there, now is the last chance
|
|
Packit |
90a5c9 |
* to perform cleanup. Normally, cleanup should have happened
|
|
Packit |
90a5c9 |
* earlier in the connection pre_close. Main reason is that
|
|
Packit |
90a5c9 |
* any ongoing requests on slave connections might still access
|
|
Packit |
90a5c9 |
* data which has, at this time, already been freed. An example
|
|
Packit |
90a5c9 |
* is mod_ssl that uses request hooks. */
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_WARNING, 0, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(10020), session,
|
|
Packit |
90a5c9 |
"session cleanup triggered by pool cleanup. "
|
|
Packit |
90a5c9 |
"this should have happened earlier already."));
|
|
Packit |
90a5c9 |
return session_cleanup(session, "pool cleanup");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_create_int(h2_session **psession,
|
|
Packit |
90a5c9 |
conn_rec *c,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
h2_ctx *ctx,
|
|
Packit |
90a5c9 |
h2_workers *workers)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
nghttp2_session_callbacks *callbacks = NULL;
|
|
Packit |
90a5c9 |
nghttp2_option *options = NULL;
|
|
Packit |
90a5c9 |
apr_allocator_t *allocator;
|
|
Packit |
90a5c9 |
apr_thread_mutex_t *mutex;
|
|
Packit |
90a5c9 |
uint32_t n;
|
|
Packit |
90a5c9 |
apr_pool_t *pool = NULL;
|
|
Packit |
90a5c9 |
h2_session *session;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
int rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*psession = NULL;
|
|
Packit |
90a5c9 |
status = apr_allocator_create(&allocator);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_allocator_max_free_set(allocator, ap_max_mem_free);
|
|
Packit |
90a5c9 |
apr_pool_create_ex(&pool, c->pool, NULL, allocator);
|
|
Packit |
90a5c9 |
if (!pool) {
|
|
Packit |
90a5c9 |
apr_allocator_destroy(allocator);
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_pool_tag(pool, "h2_session");
|
|
Packit |
90a5c9 |
apr_allocator_owner_set(allocator, pool);
|
|
Packit |
90a5c9 |
status = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_allocator_mutex_set(allocator, mutex);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session = apr_pcalloc(pool, sizeof(h2_session));
|
|
Packit |
90a5c9 |
if (!session) {
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*psession = session;
|
|
Packit |
90a5c9 |
session->id = c->id;
|
|
Packit |
90a5c9 |
session->c = c;
|
|
Packit |
90a5c9 |
session->r = r;
|
|
Packit |
90a5c9 |
session->s = h2_ctx_server_get(ctx);
|
|
Packit |
90a5c9 |
session->pool = pool;
|
|
Packit |
90a5c9 |
session->config = h2_config_sget(session->s);
|
|
Packit |
90a5c9 |
session->workers = workers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->state = H2_SESSION_ST_INIT;
|
|
Packit |
90a5c9 |
session->local.accepting = 1;
|
|
Packit |
90a5c9 |
session->remote.accepting = 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->max_stream_count = h2_config_geti(session->config,
|
|
Packit |
90a5c9 |
H2_CONF_MAX_STREAMS);
|
|
Packit |
90a5c9 |
session->max_stream_mem = h2_config_geti(session->config,
|
|
Packit |
90a5c9 |
H2_CONF_STREAM_MAX_MEM);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = apr_thread_cond_create(&session->iowait, session->pool);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->in_pending = h2_iq_create(session->pool, (int)session->max_stream_count);
|
|
Packit |
90a5c9 |
if (session->in_pending == NULL) {
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->in_process = h2_iq_create(session->pool, (int)session->max_stream_count);
|
|
Packit |
90a5c9 |
if (session->in_process == NULL) {
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->monitor = apr_pcalloc(pool, sizeof(h2_stream_monitor));
|
|
Packit |
90a5c9 |
if (session->monitor == NULL) {
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
session->monitor->ctx = session;
|
|
Packit |
90a5c9 |
session->monitor->on_state_enter = on_stream_state_enter;
|
|
Packit |
90a5c9 |
session->monitor->on_state_event = on_stream_state_event;
|
|
Packit |
90a5c9 |
session->monitor->on_event = on_stream_event;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->mplx = h2_mplx_create(c, session->pool, session->config,
|
|
Packit |
90a5c9 |
workers);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* connection input filter that feeds the session */
|
|
Packit |
90a5c9 |
session->cin = h2_filter_cin_create(session);
|
|
Packit |
90a5c9 |
ap_add_input_filter("H2_IN", session->cin, r, c);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_conn_io_init(&session->io, c, session->config);
|
|
Packit |
90a5c9 |
session->bbtmp = apr_brigade_create(session->pool, c->bucket_alloc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = init_callbacks(c, &callbacks);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, status, c, APLOGNO(02927)
|
|
Packit |
90a5c9 |
"nghttp2: error in init_callbacks");
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = nghttp2_option_new(&options);
|
|
Packit |
90a5c9 |
if (rv != 0) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, c,
|
|
Packit |
90a5c9 |
APLOGNO(02928) "nghttp2_option_new: %s",
|
|
Packit |
90a5c9 |
nghttp2_strerror(rv));
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
nghttp2_option_set_peer_max_concurrent_streams(
|
|
Packit |
90a5c9 |
options, (uint32_t)session->max_stream_count);
|
|
Packit |
90a5c9 |
/* We need to handle window updates ourself, otherwise we
|
|
Packit |
90a5c9 |
* get flooded by nghttp2. */
|
|
Packit |
90a5c9 |
nghttp2_option_set_no_auto_window_update(options, 1);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = nghttp2_session_server_new2(&session->ngh2, callbacks,
|
|
Packit |
90a5c9 |
session, options);
|
|
Packit |
90a5c9 |
nghttp2_session_callbacks_del(callbacks);
|
|
Packit |
90a5c9 |
nghttp2_option_del(options);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (rv != 0) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, c,
|
|
Packit |
90a5c9 |
APLOGNO(02929) "nghttp2_session_server_new: %s",
|
|
Packit |
90a5c9 |
nghttp2_strerror(rv));
|
|
Packit |
90a5c9 |
apr_pool_destroy(pool);
|
|
Packit |
90a5c9 |
return APR_ENOMEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
n = h2_config_geti(session->config, H2_CONF_PUSH_DIARY_SIZE);
|
|
Packit |
90a5c9 |
session->push_diary = h2_push_diary_create(session->pool, n);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APLOGcdebug(c)) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03200), session,
|
|
Packit |
90a5c9 |
"created, max_streams=%d, stream_mem=%d, "
|
|
Packit |
90a5c9 |
"workers_limit=%d, workers_max=%d, "
|
|
Packit |
90a5c9 |
"push_diary(type=%d,N=%d)"),
|
|
Packit |
90a5c9 |
(int)session->max_stream_count,
|
|
Packit |
90a5c9 |
(int)session->max_stream_mem,
|
|
Packit |
90a5c9 |
session->mplx->limit_active,
|
|
Packit |
90a5c9 |
session->mplx->max_active,
|
|
Packit |
90a5c9 |
session->push_diary->dtype,
|
|
Packit |
90a5c9 |
(int)session->push_diary->N);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_pre_cleanup_register(pool, c, session_pool_cleanup);
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_session_create(h2_session **psession,
|
|
Packit |
90a5c9 |
conn_rec *c, h2_ctx *ctx, h2_workers *workers)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return h2_session_create_int(psession, c, NULL, ctx, workers);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_session_rcreate(h2_session **psession,
|
|
Packit |
90a5c9 |
request_rec *r, h2_ctx *ctx, h2_workers *workers)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return h2_session_create_int(psession, r->connection, r, ctx, workers);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_start(h2_session *session, int *rv)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = APR_SUCCESS;
|
|
Packit |
90a5c9 |
nghttp2_settings_entry settings[3];
|
|
Packit |
90a5c9 |
size_t slen;
|
|
Packit |
90a5c9 |
int win_size;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_assert(session);
|
|
Packit |
90a5c9 |
/* Start the conversation by submitting our SETTINGS frame */
|
|
Packit |
90a5c9 |
*rv = 0;
|
|
Packit |
90a5c9 |
if (session->r) {
|
|
Packit |
90a5c9 |
const char *s, *cs;
|
|
Packit |
90a5c9 |
apr_size_t dlen;
|
|
Packit |
90a5c9 |
h2_stream * stream;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* 'h2c' mode: we should have a 'HTTP2-Settings' header with
|
|
Packit |
90a5c9 |
* base64 encoded client settings. */
|
|
Packit |
90a5c9 |
s = apr_table_get(session->r->headers_in, "HTTP2-Settings");
|
|
Packit |
90a5c9 |
if (!s) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_EINVAL, session->r,
|
|
Packit |
90a5c9 |
APLOGNO(02931)
|
|
Packit |
90a5c9 |
"HTTP2-Settings header missing in request");
|
|
Packit |
90a5c9 |
return APR_EINVAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
cs = NULL;
|
|
Packit |
90a5c9 |
dlen = h2_util_base64url_decode(&cs, s, session->pool);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (APLOGrdebug(session->r)) {
|
|
Packit |
90a5c9 |
char buffer[128];
|
|
Packit |
90a5c9 |
h2_util_hex_dump(buffer, 128, (char*)cs, dlen);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, session->r, APLOGNO(03070)
|
|
Packit |
90a5c9 |
"upgrading h2c session with HTTP2-Settings: %s -> %s (%d)",
|
|
Packit |
90a5c9 |
s, buffer, (int)dlen);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*rv = nghttp2_session_upgrade(session->ngh2, (uint8_t*)cs, dlen, NULL);
|
|
Packit |
90a5c9 |
if (*rv != 0) {
|
|
Packit |
90a5c9 |
status = APR_EINVAL;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, session->r,
|
|
Packit |
90a5c9 |
APLOGNO(02932) "nghttp2_session_upgrade: %s",
|
|
Packit |
90a5c9 |
nghttp2_strerror(*rv));
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Now we need to auto-open stream 1 for the request we got. */
|
|
Packit |
90a5c9 |
stream = h2_session_open_stream(session, 1, 0);
|
|
Packit |
90a5c9 |
if (!stream) {
|
|
Packit |
90a5c9 |
status = APR_EGENERAL;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, session->r,
|
|
Packit |
90a5c9 |
APLOGNO(02933) "open stream 1: %s",
|
|
Packit |
90a5c9 |
nghttp2_strerror(*rv));
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_stream_set_request_rec(stream, session->r, 1);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
slen = 0;
|
|
Packit |
90a5c9 |
settings[slen].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
|
Packit |
90a5c9 |
settings[slen].value = (uint32_t)session->max_stream_count;
|
|
Packit |
90a5c9 |
++slen;
|
|
Packit |
90a5c9 |
win_size = h2_config_geti(session->config, H2_CONF_WIN_SIZE);
|
|
Packit |
90a5c9 |
if (win_size != H2_INITIAL_WINDOW_SIZE) {
|
|
Packit |
90a5c9 |
settings[slen].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
|
|
Packit |
90a5c9 |
settings[slen].value = win_size;
|
|
Packit |
90a5c9 |
++slen;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03201), session,
|
|
Packit |
90a5c9 |
"start, INITIAL_WINDOW_SIZE=%ld, MAX_CONCURRENT_STREAMS=%d"),
|
|
Packit |
90a5c9 |
(long)win_size, (int)session->max_stream_count);
|
|
Packit |
90a5c9 |
*rv = nghttp2_submit_settings(session->ngh2, NGHTTP2_FLAG_NONE,
|
|
Packit |
90a5c9 |
settings, slen);
|
|
Packit |
90a5c9 |
if (*rv != 0) {
|
|
Packit |
90a5c9 |
status = APR_EGENERAL;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, status, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(02935), session,
|
|
Packit |
90a5c9 |
"nghttp2_submit_settings: %s"), nghttp2_strerror(*rv));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* use maximum possible value for connection window size. We are only
|
|
Packit |
90a5c9 |
* interested in per stream flow control. which have the initial window
|
|
Packit |
90a5c9 |
* size configured above.
|
|
Packit |
90a5c9 |
* Therefore, for our use, the connection window can only get in the
|
|
Packit |
90a5c9 |
* way. Example: if we allow 100 streams with a 32KB window each, we
|
|
Packit |
90a5c9 |
* buffer up to 3.2 MB of data. Unless we do separate connection window
|
|
Packit |
90a5c9 |
* interim updates, any smaller connection window will lead to blocking
|
|
Packit |
90a5c9 |
* in DATA flow.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
*rv = nghttp2_submit_window_update(session->ngh2, NGHTTP2_FLAG_NONE,
|
|
Packit |
90a5c9 |
0, NGHTTP2_MAX_WINDOW_SIZE - win_size);
|
|
Packit |
90a5c9 |
if (*rv != 0) {
|
|
Packit |
90a5c9 |
status = APR_EGENERAL;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, status, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(02970), session,
|
|
Packit |
90a5c9 |
"nghttp2_submit_window_update: %s"),
|
|
Packit |
90a5c9 |
nghttp2_strerror(*rv));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t on_stream_headers(h2_session *session, h2_stream *stream,
|
|
Packit |
90a5c9 |
h2_headers *headers, apr_off_t len,
|
|
Packit |
90a5c9 |
int eos);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static ssize_t stream_data_cb(nghttp2_session *ng2s,
|
|
Packit |
90a5c9 |
int32_t stream_id,
|
|
Packit |
90a5c9 |
uint8_t *buf,
|
|
Packit |
90a5c9 |
size_t length,
|
|
Packit |
90a5c9 |
uint32_t *data_flags,
|
|
Packit |
90a5c9 |
nghttp2_data_source *source,
|
|
Packit |
90a5c9 |
void *puser)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = (h2_session *)puser;
|
|
Packit |
90a5c9 |
apr_off_t nread = length;
|
|
Packit |
90a5c9 |
int eos = 0;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
ap_assert(session);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The session wants to send more DATA for the stream. We need
|
|
Packit |
90a5c9 |
* to find out how much of the requested length we can send without
|
|
Packit |
90a5c9 |
* blocking.
|
|
Packit |
90a5c9 |
* Indicate EOS when we encounter it or DEFERRED if the stream
|
|
Packit |
90a5c9 |
* should be suspended. Beware of trailers.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
(void)ng2s;
|
|
Packit |
90a5c9 |
(void)buf;
|
|
Packit |
90a5c9 |
(void)source;
|
|
Packit |
90a5c9 |
stream = h2_session_stream_get(session, stream_id);
|
|
Packit |
90a5c9 |
if (!stream) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, session->c,
|
|
Packit |
90a5c9 |
APLOGNO(02937)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): data_cb, stream not found",
|
|
Packit |
90a5c9 |
session->id, (int)stream_id);
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_stream_out_prepare(stream, &nread, &eos, NULL);
|
|
Packit |
90a5c9 |
if (nread) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "prepared no_copy, len=%ld, eos=%d"),
|
|
Packit |
90a5c9 |
(long)nread, eos);
|
|
Packit |
90a5c9 |
*data_flags |= NGHTTP2_DATA_FLAG_NO_COPY;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (status) {
|
|
Packit |
90a5c9 |
case APR_SUCCESS:
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case APR_EOF:
|
|
Packit |
90a5c9 |
eos = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case APR_ECONNRESET:
|
|
Packit |
90a5c9 |
case APR_ECONNABORTED:
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case APR_EAGAIN:
|
|
Packit |
90a5c9 |
/* If there is no data available, our session will automatically
|
|
Packit |
90a5c9 |
* suspend this stream and not ask for more data until we resume
|
|
Packit |
90a5c9 |
* it. Remember at our h2_stream that we need to do this.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
nread = 0;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03071), stream, "suspending"));
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_DEFERRED;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
nread = 0;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(02938), stream, "reading data"));
|
|
Packit |
90a5c9 |
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (eos) {
|
|
Packit |
90a5c9 |
*data_flags |= NGHTTP2_DATA_FLAG_EOF;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return (ssize_t)nread;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_stream *h2_session_push(h2_session *session, h2_stream *is,
|
|
Packit |
90a5c9 |
h2_push *push)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_stream *stream;
|
|
Packit |
90a5c9 |
h2_ngheader *ngh;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
int nid = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_req_create_ngheader(&ngh, is->pool, push->req);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
nid = nghttp2_submit_push_promise(session->ngh2, 0, is->id,
|
|
Packit |
90a5c9 |
ngh->nv, ngh->nvlen, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS || nid <= 0) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03075), is,
|
|
Packit |
90a5c9 |
"submitting push promise fail: %s"), nghttp2_strerror(nid));
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
++session->pushes_promised;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03076), is, "SERVER_PUSH %d for %s %s on %d"),
|
|
Packit |
90a5c9 |
nid, push->req->method, push->req->path, is->id);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
stream = h2_session_open_stream(session, nid, is->id);
|
|
Packit |
90a5c9 |
if (!stream) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03077), stream,
|
|
Packit |
90a5c9 |
"failed to create stream obj %d"), nid);
|
|
Packit |
90a5c9 |
/* kill the push_promise */
|
|
Packit |
90a5c9 |
nghttp2_submit_rst_stream(session->ngh2, NGHTTP2_FLAG_NONE, nid,
|
|
Packit |
90a5c9 |
NGHTTP2_INTERNAL_ERROR);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_session_set_prio(session, stream, push->priority);
|
|
Packit |
90a5c9 |
h2_stream_set_request(stream, push->req);
|
|
Packit |
90a5c9 |
++session->unsent_promises;
|
|
Packit |
90a5c9 |
return stream;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int valid_weight(float f)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int w = (int)f;
|
|
Packit |
90a5c9 |
return (w < NGHTTP2_MIN_WEIGHT? NGHTTP2_MIN_WEIGHT :
|
|
Packit |
90a5c9 |
(w > NGHTTP2_MAX_WEIGHT)? NGHTTP2_MAX_WEIGHT : w);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_session_set_prio(h2_session *session, h2_stream *stream,
|
|
Packit |
90a5c9 |
const h2_priority *prio)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = APR_SUCCESS;
|
|
Packit |
90a5c9 |
#ifdef H2_NG2_CHANGE_PRIO
|
|
Packit |
90a5c9 |
nghttp2_stream *s_grandpa, *s_parent, *s;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (prio == NULL) {
|
|
Packit |
90a5c9 |
/* we treat this as a NOP */
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
s = nghttp2_session_find_stream(session->ngh2, stream->id);
|
|
Packit |
90a5c9 |
if (!s) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "lookup of nghttp2_stream failed"));
|
|
Packit |
90a5c9 |
return APR_EINVAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s_parent = nghttp2_stream_get_parent(s);
|
|
Packit |
90a5c9 |
if (s_parent) {
|
|
Packit |
90a5c9 |
nghttp2_priority_spec ps;
|
|
Packit |
90a5c9 |
int id_parent, id_grandpa, w_parent, w;
|
|
Packit |
90a5c9 |
int rv = 0;
|
|
Packit |
90a5c9 |
const char *ptype = "AFTER";
|
|
Packit |
90a5c9 |
h2_dependency dep = prio->dependency;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
id_parent = nghttp2_stream_get_stream_id(s_parent);
|
|
Packit |
90a5c9 |
s_grandpa = nghttp2_stream_get_parent(s_parent);
|
|
Packit |
90a5c9 |
if (s_grandpa) {
|
|
Packit |
90a5c9 |
id_grandpa = nghttp2_stream_get_stream_id(s_grandpa);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* parent of parent does not exist,
|
|
Packit |
90a5c9 |
* only possible if parent == root */
|
|
Packit |
90a5c9 |
dep = H2_DEPENDANT_AFTER;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (dep) {
|
|
Packit |
90a5c9 |
case H2_DEPENDANT_INTERLEAVED:
|
|
Packit |
90a5c9 |
/* PUSHed stream is to be interleaved with initiating stream.
|
|
Packit |
90a5c9 |
* It is made a sibling of the initiating stream and gets a
|
|
Packit |
90a5c9 |
* proportional weight [1, MAX_WEIGHT] of the initiaing
|
|
Packit |
90a5c9 |
* stream weight.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ptype = "INTERLEAVED";
|
|
Packit |
90a5c9 |
w_parent = nghttp2_stream_get_weight(s_parent);
|
|
Packit |
90a5c9 |
w = valid_weight(w_parent * ((float)prio->weight / NGHTTP2_MAX_WEIGHT));
|
|
Packit |
90a5c9 |
nghttp2_priority_spec_init(&ps, id_grandpa, w, 0);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case H2_DEPENDANT_BEFORE:
|
|
Packit |
90a5c9 |
/* PUSHed stream os to be sent BEFORE the initiating stream.
|
|
Packit |
90a5c9 |
* It gets the same weight as the initiating stream, replaces
|
|
Packit |
90a5c9 |
* that stream in the dependency tree and has the initiating
|
|
Packit |
90a5c9 |
* stream as child.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ptype = "BEFORE";
|
|
Packit |
90a5c9 |
w = w_parent = nghttp2_stream_get_weight(s_parent);
|
|
Packit |
90a5c9 |
nghttp2_priority_spec_init(&ps, stream->id, w_parent, 0);
|
|
Packit |
90a5c9 |
id_grandpa = nghttp2_stream_get_stream_id(s_grandpa);
|
|
Packit |
90a5c9 |
rv = nghttp2_session_change_stream_priority(session->ngh2, id_parent, &ps);
|
|
Packit |
90a5c9 |
if (rv < 0) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(03202)
|
|
Packit |
90a5c9 |
"h2_stream(%ld-%d): PUSH BEFORE, weight=%d, "
|
|
Packit |
90a5c9 |
"depends=%d, returned=%d",
|
|
Packit |
90a5c9 |
session->id, id_parent, ps.weight, ps.stream_id, rv);
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
nghttp2_priority_spec_init(&ps, id_grandpa, w, 0);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case H2_DEPENDANT_AFTER:
|
|
Packit |
90a5c9 |
/* The PUSHed stream is to be sent after the initiating stream.
|
|
Packit |
90a5c9 |
* Give if the specified weight and let it depend on the intiating
|
|
Packit |
90a5c9 |
* stream.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
/* fall through, it's the default */
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
nghttp2_priority_spec_init(&ps, id_parent, valid_weight(prio->weight), 0);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = nghttp2_session_change_stream_priority(session->ngh2, stream->id, &ps);
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
""H2_STRM_LOG(APLOGNO(03203), stream,
|
|
Packit |
90a5c9 |
"PUSH %s, weight=%d, depends=%d, returned=%d"),
|
|
Packit |
90a5c9 |
ptype, ps.weight, ps.stream_id, rv);
|
|
Packit |
90a5c9 |
status = (rv < 0)? APR_EGENERAL : APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
(void)session;
|
|
Packit |
90a5c9 |
(void)stream;
|
|
Packit |
90a5c9 |
(void)prio;
|
|
Packit |
90a5c9 |
(void)valid_weight;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int h2_session_push_enabled(h2_session *session)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* iff we can and they can and want */
|
|
Packit |
90a5c9 |
return (session->remote.accepting /* remote GOAWAY received */
|
|
Packit |
90a5c9 |
&& h2_config_geti(session->config, H2_CONF_PUSH)
|
|
Packit |
90a5c9 |
&& nghttp2_session_get_remote_settings(session->ngh2,
|
|
Packit |
90a5c9 |
NGHTTP2_SETTINGS_ENABLE_PUSH));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_send(h2_session *session)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_interval_time_t saved_timeout;
|
|
Packit |
90a5c9 |
int rv;
|
|
Packit |
90a5c9 |
apr_socket_t *socket;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
socket = ap_get_conn_socket(session->c);
|
|
Packit |
90a5c9 |
if (socket) {
|
|
Packit |
90a5c9 |
apr_socket_timeout_get(socket, &saved_timeout);
|
|
Packit |
90a5c9 |
apr_socket_timeout_set(socket, session->s->timeout);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = nghttp2_session_send(session->ngh2);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (socket) {
|
|
Packit |
90a5c9 |
apr_socket_timeout_set(socket, saved_timeout);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
session->have_written = 1;
|
|
Packit |
90a5c9 |
if (rv != 0 && rv != NGHTTP2_ERR_WOULDBLOCK) {
|
|
Packit |
90a5c9 |
if (nghttp2_is_fatal(rv)) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_PROTO_ERROR, rv, nghttp2_strerror(rv));
|
|
Packit |
90a5c9 |
return APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->unsent_promises = 0;
|
|
Packit |
90a5c9 |
session->unsent_submits = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* headers for the stream are ready.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static apr_status_t on_stream_headers(h2_session *session, h2_stream *stream,
|
|
Packit |
90a5c9 |
h2_headers *headers, apr_off_t len,
|
|
Packit |
90a5c9 |
int eos)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = APR_SUCCESS;
|
|
Packit |
90a5c9 |
int rv = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_assert(session);
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "on_headers"));
|
|
Packit |
90a5c9 |
if (headers->status < 100) {
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, headers->status);
|
|
Packit |
90a5c9 |
goto leave;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (stream->has_response) {
|
|
Packit |
90a5c9 |
h2_ngheader *nh;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_res_create_ngtrailer(&nh, stream->pool, headers);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03072), stream, "submit %d trailers"),
|
|
Packit |
90a5c9 |
(int)nh->nvlen);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
rv = nghttp2_submit_trailer(session->ngh2, stream->id,
|
|
Packit |
90a5c9 |
nh->nv, nh->nvlen);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(10024), stream, "invalid trailers"));
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, NGHTTP2_PROTOCOL_ERROR);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
goto leave;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
nghttp2_data_provider provider, *pprovider = NULL;
|
|
Packit |
90a5c9 |
h2_ngheader *ngh;
|
|
Packit |
90a5c9 |
const char *note;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03073), stream, "submit response %d, REMOTE_WINDOW_SIZE=%u"),
|
|
Packit |
90a5c9 |
headers->status,
|
|
Packit |
90a5c9 |
(unsigned int)nghttp2_session_get_stream_remote_window_size(session->ngh2, stream->id));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!eos || len > 0) {
|
|
Packit |
90a5c9 |
memset(&provider, 0, sizeof(provider));
|
|
Packit |
90a5c9 |
provider.source.fd = stream->id;
|
|
Packit |
90a5c9 |
provider.read_callback = stream_data_cb;
|
|
Packit |
90a5c9 |
pprovider = &provider;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* If this stream is not a pushed one itself,
|
|
Packit |
90a5c9 |
* and HTTP/2 server push is enabled here,
|
|
Packit |
90a5c9 |
* and the response HTTP status is not sth >= 400,
|
|
Packit |
90a5c9 |
* and the remote side has pushing enabled,
|
|
Packit |
90a5c9 |
* -> find and perform any pushes on this stream
|
|
Packit |
90a5c9 |
* *before* we submit the stream response itself.
|
|
Packit |
90a5c9 |
* This helps clients avoid opening new streams on Link
|
|
Packit |
90a5c9 |
* headers that get pushed right afterwards.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* *) the response code is relevant, as we do not want to
|
|
Packit |
90a5c9 |
* make pushes on 401 or 403 codes and friends.
|
|
Packit |
90a5c9 |
* And if we see a 304, we do not push either
|
|
Packit |
90a5c9 |
* as the client, having this resource in its cache, might
|
|
Packit |
90a5c9 |
* also have the pushed ones as well.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!stream->initiated_on
|
|
Packit |
90a5c9 |
&& !stream->has_response
|
|
Packit |
90a5c9 |
&& stream->request && stream->request->method
|
|
Packit |
90a5c9 |
&& !strcmp("GET", stream->request->method)
|
|
Packit |
90a5c9 |
&& (headers->status < 400)
|
|
Packit |
90a5c9 |
&& (headers->status != 304)
|
|
Packit |
90a5c9 |
&& h2_session_push_enabled(session)) {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_stream_submit_pushes(stream, headers);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!stream->pref_priority) {
|
|
Packit |
90a5c9 |
stream->pref_priority = h2_stream_get_priority(stream, headers);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
h2_session_set_prio(session, stream, stream->pref_priority);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
note = apr_table_get(headers->notes, H2_FILTER_DEBUG_NOTE);
|
|
Packit |
90a5c9 |
if (note && !strcmp("on", note)) {
|
|
Packit |
90a5c9 |
int32_t connFlowIn, connFlowOut;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
connFlowIn = nghttp2_session_get_effective_local_window_size(session->ngh2);
|
|
Packit |
90a5c9 |
connFlowOut = nghttp2_session_get_remote_window_size(session->ngh2);
|
|
Packit |
90a5c9 |
headers = h2_headers_copy(stream->pool, headers);
|
|
Packit |
90a5c9 |
apr_table_setn(headers->headers, "conn-flow-in",
|
|
Packit |
90a5c9 |
apr_itoa(stream->pool, connFlowIn));
|
|
Packit |
90a5c9 |
apr_table_setn(headers->headers, "conn-flow-out",
|
|
Packit |
90a5c9 |
apr_itoa(stream->pool, connFlowOut));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (headers->status == 103
|
|
Packit |
90a5c9 |
&& !h2_config_geti(session->config, H2_CONF_EARLY_HINTS)) {
|
|
Packit |
90a5c9 |
/* suppress sending this to the client, it might have triggered
|
|
Packit |
90a5c9 |
* pushes and served its purpose nevertheless */
|
|
Packit |
90a5c9 |
rv = 0;
|
|
Packit |
90a5c9 |
goto leave;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_res_create_ngheader(&ngh, stream->pool, headers);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
rv = nghttp2_submit_response(session->ngh2, stream->id,
|
|
Packit |
90a5c9 |
ngh->nv, ngh->nvlen, pprovider);
|
|
Packit |
90a5c9 |
stream->has_response = h2_headers_are_response(headers);
|
|
Packit |
90a5c9 |
session->have_written = 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (stream->initiated_on) {
|
|
Packit |
90a5c9 |
++session->pushes_submitted;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
++session->responses_submitted;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(10025), stream, "invalid response"));
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, NGHTTP2_PROTOCOL_ERROR);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
leave:
|
|
Packit |
90a5c9 |
if (nghttp2_is_fatal(rv)) {
|
|
Packit |
90a5c9 |
status = APR_EGENERAL;
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_PROTO_ERROR, rv, nghttp2_strerror(rv));
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, status, session->c,
|
|
Packit |
90a5c9 |
APLOGNO(02940) "submit_response: %s",
|
|
Packit |
90a5c9 |
nghttp2_strerror(rv));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
++session->unsent_submits;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Unsent push promises are written immediately, as nghttp2
|
|
Packit |
90a5c9 |
* 1.5.0 realizes internal stream data structures only on
|
|
Packit |
90a5c9 |
* send and we might need them for other submits.
|
|
Packit |
90a5c9 |
* Also, to conserve memory, we send at least every 10 submits
|
|
Packit |
90a5c9 |
* so that nghttp2 does not buffer all outbound items too
|
|
Packit |
90a5c9 |
* long.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS
|
|
Packit |
90a5c9 |
&& (session->unsent_promises || session->unsent_submits > 10)) {
|
|
Packit |
90a5c9 |
status = h2_session_send(session);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* A stream was resumed as new response/output data arrived.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static apr_status_t on_stream_resume(void *ctx, h2_stream *stream)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = ctx;
|
|
Packit |
90a5c9 |
apr_status_t status = APR_EAGAIN;
|
|
Packit |
90a5c9 |
int rv;
|
|
Packit |
90a5c9 |
apr_off_t len = 0;
|
|
Packit |
90a5c9 |
int eos = 0;
|
|
Packit |
90a5c9 |
h2_headers *headers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_assert(stream);
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "on_resume"));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
send_headers:
|
|
Packit |
90a5c9 |
headers = NULL;
|
|
Packit |
90a5c9 |
status = h2_stream_out_prepare(stream, &len, &eos, &headers);
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, status, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "prepared len=%ld, eos=%d"),
|
|
Packit |
90a5c9 |
(long)len, eos);
|
|
Packit |
90a5c9 |
if (headers) {
|
|
Packit |
90a5c9 |
status = on_stream_headers(session, stream, headers, len, eos);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS || stream->rst_error) {
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
goto send_headers;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status != APR_EAGAIN) {
|
|
Packit |
90a5c9 |
/* we have DATA to send */
|
|
Packit |
90a5c9 |
if (!stream->has_response) {
|
|
Packit |
90a5c9 |
/* but no response */
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(03466), stream,
|
|
Packit |
90a5c9 |
"no response, RST_STREAM"));
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, H2_ERR_PROTOCOL_ERROR);
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
rv = nghttp2_session_resume_data(session->ngh2, stream->id);
|
|
Packit |
90a5c9 |
session->have_written = 1;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, nghttp2_is_fatal(rv)?
|
|
Packit |
90a5c9 |
APLOG_ERR : APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_LOG(APLOGNO(02936), stream, "resumed"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_in_flush(h2_session *session)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int id;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((id = h2_iq_shift(session->in_process)) > 0) {
|
|
Packit |
90a5c9 |
h2_stream *stream = h2_session_stream_get(session, id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
ap_assert(!stream->scheduled);
|
|
Packit |
90a5c9 |
if (h2_stream_prep_processing(stream) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
h2_mplx_process(session->mplx, stream, stream_pri_cmp, session);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
h2_stream_rst(stream, H2_ERR_INTERNAL_ERROR);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((id = h2_iq_shift(session->in_pending)) > 0) {
|
|
Packit |
90a5c9 |
h2_stream *stream = h2_session_stream_get(session, id);
|
|
Packit |
90a5c9 |
if (stream) {
|
|
Packit |
90a5c9 |
h2_stream_flush_input(stream);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t session_read(h2_session *session, apr_size_t readlen, int block)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status, rstatus = APR_EAGAIN;
|
|
Packit |
90a5c9 |
conn_rec *c = session->c;
|
|
Packit |
90a5c9 |
apr_off_t read_start = session->io.bytes_read;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (1) {
|
|
Packit |
90a5c9 |
/* H2_IN filter handles all incoming data against the session.
|
|
Packit |
90a5c9 |
* We just pull at the filter chain to make it happen */
|
|
Packit |
90a5c9 |
status = ap_get_brigade(c->input_filters,
|
|
Packit |
90a5c9 |
session->bbtmp, AP_MODE_READBYTES,
|
|
Packit |
90a5c9 |
block? APR_BLOCK_READ : APR_NONBLOCK_READ,
|
|
Packit |
90a5c9 |
H2MAX(APR_BUCKET_BUFF_SIZE, readlen));
|
|
Packit |
90a5c9 |
/* get rid of any possible data we do not expect to get */
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(session->bbtmp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (status) {
|
|
Packit |
90a5c9 |
case APR_SUCCESS:
|
|
Packit |
90a5c9 |
/* successful read, reset our idle timers */
|
|
Packit |
90a5c9 |
rstatus = APR_SUCCESS;
|
|
Packit |
90a5c9 |
if (block) {
|
|
Packit |
90a5c9 |
/* successful blocked read, try unblocked to
|
|
Packit |
90a5c9 |
* get more. */
|
|
Packit |
90a5c9 |
block = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case APR_EAGAIN:
|
|
Packit |
90a5c9 |
return rstatus;
|
|
Packit |
90a5c9 |
case APR_TIMEUP:
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
if (session->io.bytes_read == read_start) {
|
|
Packit |
90a5c9 |
/* first attempt failed */
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_ETIMEDOUT(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ECONNABORTED(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ECONNRESET(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_EOF(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_EBADF(status)) {
|
|
Packit |
90a5c9 |
/* common status for a client that has left */
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "input gone"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* uncommon status, log on INFO so that we see this */
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_DEBUG, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(02950), session,
|
|
Packit |
90a5c9 |
"error reading, terminating"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* subsequent failure after success(es), return initial
|
|
Packit |
90a5c9 |
* status. */
|
|
Packit |
90a5c9 |
return rstatus;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((session->io.bytes_read - read_start) > readlen) {
|
|
Packit |
90a5c9 |
/* read enough in one go, give write a chance */
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "read enough, returning"));
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return rstatus;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t h2_session_read(h2_session *session, int block)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = session_read(session, session->max_stream_mem
|
|
Packit |
90a5c9 |
* H2MAX(2, session->open_streams),
|
|
Packit |
90a5c9 |
block);
|
|
Packit |
90a5c9 |
h2_session_in_flush(session);
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *StateNames[] = {
|
|
Packit |
90a5c9 |
"INIT", /* H2_SESSION_ST_INIT */
|
|
Packit |
90a5c9 |
"DONE", /* H2_SESSION_ST_DONE */
|
|
Packit |
90a5c9 |
"IDLE", /* H2_SESSION_ST_IDLE */
|
|
Packit |
90a5c9 |
"BUSY", /* H2_SESSION_ST_BUSY */
|
|
Packit |
90a5c9 |
"WAIT", /* H2_SESSION_ST_WAIT */
|
|
Packit |
90a5c9 |
"CLEANUP", /* H2_SESSION_ST_CLEANUP */
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
const char *h2_session_state_str(h2_session_state state)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (state >= (sizeof(StateNames)/sizeof(StateNames[0]))) {
|
|
Packit |
90a5c9 |
return "unknown";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return StateNames[state];
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void update_child_status(h2_session *session, int status, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* Assume that we also change code/msg when something really happened and
|
|
Packit |
90a5c9 |
* avoid updating the scoreboard in between */
|
|
Packit |
90a5c9 |
if (session->last_status_code != status
|
|
Packit |
90a5c9 |
|| session->last_status_msg != msg) {
|
|
Packit |
90a5c9 |
apr_snprintf(session->status, sizeof(session->status),
|
|
Packit |
90a5c9 |
"%s, streams: %d/%d/%d/%d/%d (open/recv/resp/push/rst)",
|
|
Packit |
90a5c9 |
msg? msg : "-",
|
|
Packit |
90a5c9 |
(int)session->open_streams,
|
|
Packit |
90a5c9 |
(int)session->remote.emitted_count,
|
|
Packit |
90a5c9 |
(int)session->responses_submitted,
|
|
Packit |
90a5c9 |
(int)session->pushes_submitted,
|
|
Packit |
90a5c9 |
(int)session->pushes_reset + session->streams_reset);
|
|
Packit |
90a5c9 |
ap_update_child_status_descr(session->c->sbh, status, session->status);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void transit(h2_session *session, const char *action, h2_session_state nstate)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_time_t timeout;
|
|
Packit |
90a5c9 |
int ostate, loglvl;
|
|
Packit |
90a5c9 |
const char *s;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (session->state != nstate) {
|
|
Packit |
90a5c9 |
ostate = session->state;
|
|
Packit |
90a5c9 |
session->state = nstate;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
loglvl = APLOG_DEBUG;
|
|
Packit |
90a5c9 |
if ((ostate == H2_SESSION_ST_BUSY && nstate == H2_SESSION_ST_WAIT)
|
|
Packit |
90a5c9 |
|| (ostate == H2_SESSION_ST_WAIT && nstate == H2_SESSION_ST_BUSY)){
|
|
Packit |
90a5c9 |
loglvl = APLOG_TRACE1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, loglvl, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03078), session,
|
|
Packit |
90a5c9 |
"transit [%s] -- %s --> [%s]"),
|
|
Packit |
90a5c9 |
h2_session_state_str(ostate), action,
|
|
Packit |
90a5c9 |
h2_session_state_str(nstate));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_IDLE:
|
|
Packit |
90a5c9 |
if (!session->remote.emitted_count) {
|
|
Packit |
90a5c9 |
/* on fresh connections, with async mpm, do not return
|
|
Packit |
90a5c9 |
* to mpm for a second. This gives the first request a better
|
|
Packit |
90a5c9 |
* chance to arrive (und connection leaving IDLE state).
|
|
Packit |
90a5c9 |
* If we return to mpm right away, this connection has the
|
|
Packit |
90a5c9 |
* same chance of being cleaned up by the mpm as connections
|
|
Packit |
90a5c9 |
* that already served requests - not fair. */
|
|
Packit |
90a5c9 |
session->idle_sync_until = apr_time_now() + apr_time_from_sec(1);
|
|
Packit |
90a5c9 |
s = "timeout";
|
|
Packit |
90a5c9 |
timeout = H2MAX(session->s->timeout, session->s->keep_alive_timeout);
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_BUSY_READ, "idle");
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG("", session, "enter idle, timeout = %d sec"),
|
|
Packit |
90a5c9 |
(int)apr_time_sec(H2MAX(session->s->timeout, session->s->keep_alive_timeout)));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (session->open_streams) {
|
|
Packit |
90a5c9 |
s = "timeout";
|
|
Packit |
90a5c9 |
timeout = session->s->keep_alive_timeout;
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_BUSY_KEEPALIVE, "idle");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* normal keepalive setup */
|
|
Packit |
90a5c9 |
s = "keepalive";
|
|
Packit |
90a5c9 |
timeout = session->s->keep_alive_timeout;
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_BUSY_KEEPALIVE, "idle");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
session->idle_until = apr_time_now() + timeout;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG("", session, "enter idle, %s = %d sec"),
|
|
Packit |
90a5c9 |
s, (int)apr_time_sec(timeout));
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_DONE:
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_CLOSING, "done");
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_init(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_INIT:
|
|
Packit |
90a5c9 |
transit(session, "init", H2_SESSION_ST_BUSY);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_local_goaway(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
cleanup_unprocessed_streams(session);
|
|
Packit |
90a5c9 |
if (!session->remote.shutdown) {
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_CLOSING, "local goaway");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
transit(session, "local goaway", H2_SESSION_ST_DONE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_remote_goaway(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (!session->remote.shutdown) {
|
|
Packit |
90a5c9 |
session->remote.error = arg;
|
|
Packit |
90a5c9 |
session->remote.accepting = 0;
|
|
Packit |
90a5c9 |
session->remote.shutdown = 1;
|
|
Packit |
90a5c9 |
cleanup_unprocessed_streams(session);
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_CLOSING, "remote goaway");
|
|
Packit |
90a5c9 |
transit(session, "remote goaway", H2_SESSION_ST_DONE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_conn_error(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_INIT:
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_DONE:
|
|
Packit |
90a5c9 |
/* just leave */
|
|
Packit |
90a5c9 |
transit(session, "conn error", H2_SESSION_ST_DONE);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03401), session,
|
|
Packit |
90a5c9 |
"conn error -> shutdown"));
|
|
Packit |
90a5c9 |
h2_session_shutdown(session, arg, msg, 0);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_proto_error(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (!session->local.shutdown) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03402), session,
|
|
Packit |
90a5c9 |
"proto error -> shutdown"));
|
|
Packit |
90a5c9 |
h2_session_shutdown(session, arg, msg, 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_conn_timeout(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
transit(session, msg, H2_SESSION_ST_DONE);
|
|
Packit |
90a5c9 |
if (!session->local.shutdown) {
|
|
Packit |
90a5c9 |
h2_session_shutdown(session, arg, msg, 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_no_io(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_BUSY:
|
|
Packit |
90a5c9 |
/* Nothing to READ, nothing to WRITE on the master connection.
|
|
Packit |
90a5c9 |
* Possible causes:
|
|
Packit |
90a5c9 |
* - we wait for the client to send us sth
|
|
Packit |
90a5c9 |
* - we wait for started tasks to produce output
|
|
Packit |
90a5c9 |
* - we have finished all streams and the client has sent GO_AWAY
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "NO_IO event, %d streams open"),
|
|
Packit |
90a5c9 |
session->open_streams);
|
|
Packit |
90a5c9 |
h2_conn_io_flush(&session->io);
|
|
Packit |
90a5c9 |
if (session->open_streams > 0) {
|
|
Packit |
90a5c9 |
if (h2_mplx_awaits_data(session->mplx)) {
|
|
Packit |
90a5c9 |
/* waiting for at least one stream to produce data */
|
|
Packit |
90a5c9 |
transit(session, "no io", H2_SESSION_ST_WAIT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* we have streams open, and all are submitted and none
|
|
Packit |
90a5c9 |
* is suspended. The only thing keeping us from WRITEing
|
|
Packit |
90a5c9 |
* more must be the flow control.
|
|
Packit |
90a5c9 |
* This means we only wait for WINDOW_UPDATE from the
|
|
Packit |
90a5c9 |
* client and can block on READ. */
|
|
Packit |
90a5c9 |
transit(session, "no io (flow wait)", H2_SESSION_ST_IDLE);
|
|
Packit |
90a5c9 |
/* Make sure we have flushed all previously written output
|
|
Packit |
90a5c9 |
* so that the client will react. */
|
|
Packit |
90a5c9 |
if (h2_conn_io_flush(&session->io) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (session->local.accepting) {
|
|
Packit |
90a5c9 |
/* When we have no streams, but accept new, switch to idle */
|
|
Packit |
90a5c9 |
transit(session, "no io (keepalive)", H2_SESSION_ST_IDLE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* We are no longer accepting new streams and there are
|
|
Packit |
90a5c9 |
* none left. Time to leave. */
|
|
Packit |
90a5c9 |
h2_session_shutdown(session, arg, msg, 0);
|
|
Packit |
90a5c9 |
transit(session, "no io", H2_SESSION_ST_DONE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_frame_rcvd(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_IDLE:
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_WAIT:
|
|
Packit |
90a5c9 |
transit(session, "frame received", H2_SESSION_ST_BUSY);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_stream_change(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_IDLE:
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_WAIT:
|
|
Packit |
90a5c9 |
transit(session, "stream change", H2_SESSION_ST_BUSY);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_ngh2_done(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_DONE:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
transit(session, "nghttp2 done", H2_SESSION_ST_DONE);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_mpm_stopping(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_DONE:
|
|
Packit |
90a5c9 |
/* nop */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
h2_session_shutdown_notice(session);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void h2_session_ev_pre_close(h2_session *session, int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session_shutdown(session, arg, msg, 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ev_stream_open(h2_session *session, h2_stream *stream)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_iq_append(session->in_process, stream->id);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ev_stream_closed(h2_session *session, h2_stream *stream)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_bucket *b;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (H2_STREAM_CLIENT_INITIATED(stream->id)
|
|
Packit |
90a5c9 |
&& (stream->id > session->local.completed_max)) {
|
|
Packit |
90a5c9 |
session->local.completed_max = stream->id;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_IDLE:
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The stream might have data in the buffers of the main connection.
|
|
Packit |
90a5c9 |
* We can only free the allocated resources once all had been written.
|
|
Packit |
90a5c9 |
* Send a special buckets on the connection that gets destroyed when
|
|
Packit |
90a5c9 |
* all preceding data has been handled. On its destruction, it is safe
|
|
Packit |
90a5c9 |
* to purge all resources of the stream. */
|
|
Packit |
90a5c9 |
b = h2_bucket_eos_create(session->c->bucket_alloc, stream);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(session->bbtmp, b);
|
|
Packit |
90a5c9 |
h2_conn_io_pass(&session->io, session->bbtmp);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(session->bbtmp);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void on_stream_state_enter(void *ctx, h2_stream *stream)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = ctx;
|
|
Packit |
90a5c9 |
/* stream entered a new state */
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
|
|
Packit |
90a5c9 |
H2_STRM_MSG(stream, "entered state"));
|
|
Packit |
90a5c9 |
switch (stream->state) {
|
|
Packit |
90a5c9 |
case H2_SS_IDLE: /* stream was created */
|
|
Packit |
90a5c9 |
++session->open_streams;
|
|
Packit |
90a5c9 |
if (H2_STREAM_CLIENT_INITIATED(stream->id)) {
|
|
Packit |
90a5c9 |
++session->remote.emitted_count;
|
|
Packit |
90a5c9 |
if (stream->id > session->remote.emitted_max) {
|
|
Packit |
90a5c9 |
session->remote.emitted_max = stream->id;
|
|
Packit |
90a5c9 |
session->local.accepted_max = stream->id;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if (stream->id > session->local.emitted_max) {
|
|
Packit |
90a5c9 |
++session->local.emitted_count;
|
|
Packit |
90a5c9 |
session->remote.emitted_max = stream->id;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SS_OPEN: /* stream has request headers */
|
|
Packit |
90a5c9 |
case H2_SS_RSVD_L: /* stream has request headers */
|
|
Packit |
90a5c9 |
ev_stream_open(session, stream);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SS_CLOSED_L: /* stream output was closed */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SS_CLOSED_R: /* stream input was closed */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SS_CLOSED: /* stream in+out were closed */
|
|
Packit |
90a5c9 |
--session->open_streams;
|
|
Packit |
90a5c9 |
ev_stream_closed(session, stream);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SS_CLEANUP:
|
|
Packit |
90a5c9 |
h2_mplx_stream_cleanup(session->mplx, stream);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_STREAM_CHANGE, 0, "stream state change");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void on_stream_event(void *ctx, h2_stream *stream,
|
|
Packit |
90a5c9 |
h2_stream_event_t ev)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = ctx;
|
|
Packit |
90a5c9 |
switch (ev) {
|
|
Packit |
90a5c9 |
case H2_SEV_IN_DATA_PENDING:
|
|
Packit |
90a5c9 |
h2_iq_append(session->in_pending, stream->id);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* NOP */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void on_stream_state_event(void *ctx, h2_stream *stream,
|
|
Packit |
90a5c9 |
h2_stream_event_t ev)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
h2_session *session = ctx;
|
|
Packit |
90a5c9 |
switch (ev) {
|
|
Packit |
90a5c9 |
case H2_SEV_CANCELLED:
|
|
Packit |
90a5c9 |
if (session->state != H2_SESSION_ST_DONE) {
|
|
Packit |
90a5c9 |
nghttp2_submit_rst_stream(session->ngh2, NGHTTP2_FLAG_NONE,
|
|
Packit |
90a5c9 |
stream->id, stream->rst_error);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* NOP */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void dispatch_event(h2_session *session, h2_session_event_t ev,
|
|
Packit |
90a5c9 |
int arg, const char *msg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (ev) {
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_INIT:
|
|
Packit |
90a5c9 |
h2_session_ev_init(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_LOCAL_GOAWAY:
|
|
Packit |
90a5c9 |
h2_session_ev_local_goaway(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_REMOTE_GOAWAY:
|
|
Packit |
90a5c9 |
h2_session_ev_remote_goaway(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_CONN_ERROR:
|
|
Packit |
90a5c9 |
h2_session_ev_conn_error(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_PROTO_ERROR:
|
|
Packit |
90a5c9 |
h2_session_ev_proto_error(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_CONN_TIMEOUT:
|
|
Packit |
90a5c9 |
h2_session_ev_conn_timeout(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_NO_IO:
|
|
Packit |
90a5c9 |
h2_session_ev_no_io(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_FRAME_RCVD:
|
|
Packit |
90a5c9 |
h2_session_ev_frame_rcvd(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_NGH2_DONE:
|
|
Packit |
90a5c9 |
h2_session_ev_ngh2_done(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_MPM_STOPPING:
|
|
Packit |
90a5c9 |
h2_session_ev_mpm_stopping(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_PRE_CLOSE:
|
|
Packit |
90a5c9 |
h2_session_ev_pre_close(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case H2_SESSION_EV_STREAM_CHANGE:
|
|
Packit |
90a5c9 |
h2_session_ev_stream_change(session, arg, msg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "unknown event %d"), ev);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* trigger window updates, stream resumes and submits */
|
|
Packit |
90a5c9 |
static apr_status_t dispatch_master(h2_session *session) {
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = h2_mplx_dispatch_master_events(session->mplx,
|
|
Packit |
90a5c9 |
on_stream_resume, session);
|
|
Packit |
90a5c9 |
if (status == APR_EAGAIN) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "no master event available"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "dispatch error"));
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR,
|
|
Packit |
90a5c9 |
H2_ERR_INTERNAL_ERROR, "dispatch error");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const int MAX_WAIT_MICROS = 200 * 1000;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_session_process(h2_session *session, int async)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status = APR_SUCCESS;
|
|
Packit |
90a5c9 |
conn_rec *c = session->c;
|
|
Packit |
90a5c9 |
int rv, mpm_state, trace = APLOGctrace3(c);
|
|
Packit |
90a5c9 |
apr_time_t now;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (trace) {
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE3, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "process start, async=%d"), async);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (session->state != H2_SESSION_ST_DONE) {
|
|
Packit |
90a5c9 |
now = apr_time_now();
|
|
Packit |
90a5c9 |
session->have_read = session->have_written = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (session->local.accepting
|
|
Packit |
90a5c9 |
&& !ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) {
|
|
Packit |
90a5c9 |
if (mpm_state == AP_MPMQ_STOPPING) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_MPM_STOPPING, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
session->status[0] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (session->state) {
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_INIT:
|
|
Packit |
90a5c9 |
ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c);
|
|
Packit |
90a5c9 |
if (!h2_is_acceptable_connection(c, 1)) {
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_BUSY_READ,
|
|
Packit |
90a5c9 |
"inadequate security");
|
|
Packit |
90a5c9 |
h2_session_shutdown(session,
|
|
Packit |
90a5c9 |
NGHTTP2_INADEQUATE_SECURITY, NULL, 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
update_child_status(session, SERVER_BUSY_READ, "init");
|
|
Packit |
90a5c9 |
status = h2_session_start(session, &rv;;
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03079), session,
|
|
Packit |
90a5c9 |
"started on %s:%d"),
|
|
Packit |
90a5c9 |
session->s->server_hostname,
|
|
Packit |
90a5c9 |
c->local_addr->port);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
dispatch_event(session,
|
|
Packit |
90a5c9 |
H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_INIT, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_IDLE:
|
|
Packit |
90a5c9 |
if (session->idle_until && (apr_time_now() + session->idle_delay) > session->idle_until) {
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE1, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "idle, timeout reached, closing"));
|
|
Packit |
90a5c9 |
if (session->idle_delay) {
|
|
Packit |
90a5c9 |
apr_table_setn(session->c->notes, "short-lingering-close", "1");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_TIMEOUT, 0, "timeout");
|
|
Packit |
90a5c9 |
goto out;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (session->idle_delay) {
|
|
Packit |
90a5c9 |
/* we are less interested in spending time on this connection */
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE2, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "session is idle (%ld ms), idle wait %ld sec left"),
|
|
Packit |
90a5c9 |
(long)apr_time_as_msec(session->idle_delay),
|
|
Packit |
90a5c9 |
(long)apr_time_sec(session->idle_until - now));
|
|
Packit |
90a5c9 |
apr_sleep(session->idle_delay);
|
|
Packit |
90a5c9 |
session->idle_delay = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_conn_io_flush(&session->io);
|
|
Packit |
90a5c9 |
if (async && !session->r && (now > session->idle_sync_until)) {
|
|
Packit |
90a5c9 |
if (trace) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session,
|
|
Packit |
90a5c9 |
"nonblock read, %d streams open"),
|
|
Packit |
90a5c9 |
session->open_streams);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
status = h2_session_read(session, 0);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
session->have_read = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_EAGAIN(status) || APR_STATUS_IS_TIMEUP(status)) {
|
|
Packit |
90a5c9 |
status = APR_EAGAIN;
|
|
Packit |
90a5c9 |
goto out;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03403), session,
|
|
Packit |
90a5c9 |
"no data, error"));
|
|
Packit |
90a5c9 |
dispatch_event(session,
|
|
Packit |
90a5c9 |
H2_SESSION_EV_CONN_ERROR, 0, "timeout");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* make certain, we send everything before we idle */
|
|
Packit |
90a5c9 |
if (trace) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session,
|
|
Packit |
90a5c9 |
"sync, stutter 1-sec, %d streams open"),
|
|
Packit |
90a5c9 |
session->open_streams);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* We wait in smaller increments, using a 1 second timeout.
|
|
Packit |
90a5c9 |
* That gives us the chance to check for MPMQ_STOPPING often.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
status = h2_mplx_idle(session->mplx);
|
|
Packit |
90a5c9 |
if (status == APR_EAGAIN) {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR,
|
|
Packit |
90a5c9 |
H2_ERR_ENHANCE_YOUR_CALM, "less is more");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
h2_filter_cin_timeout_set(session->cin, apr_time_from_sec(1));
|
|
Packit |
90a5c9 |
status = h2_session_read(session, 1);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
session->have_read = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status == APR_EAGAIN) {
|
|
Packit |
90a5c9 |
/* nothing to read */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_TIMEUP(status)) {
|
|
Packit |
90a5c9 |
/* continue reading handling */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_ECONNABORTED(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ECONNRESET(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_EOF(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_EBADF(status)) {
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE3, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "input gone"));
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE3, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session,
|
|
Packit |
90a5c9 |
"(1 sec timeout) read failed"));
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, "error");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (nghttp2_session_want_write(session->ngh2)) {
|
|
Packit |
90a5c9 |
ap_update_child_status(session->c->sbh, SERVER_BUSY_WRITE, NULL);
|
|
Packit |
90a5c9 |
status = h2_session_send(session);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
status = h2_conn_io_flush(&session->io);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR,
|
|
Packit |
90a5c9 |
H2_ERR_INTERNAL_ERROR, "writing");
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_BUSY:
|
|
Packit |
90a5c9 |
if (nghttp2_session_want_read(session->ngh2)) {
|
|
Packit |
90a5c9 |
ap_update_child_status(session->c->sbh, SERVER_BUSY_READ, NULL);
|
|
Packit |
90a5c9 |
h2_filter_cin_timeout_set(session->cin, session->s->timeout);
|
|
Packit |
90a5c9 |
status = h2_session_read(session, 0);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
session->have_read = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status == APR_EAGAIN) {
|
|
Packit |
90a5c9 |
/* nothing to read */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_TIMEUP(status)) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_TIMEOUT, 0, NULL);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = dispatch_master(session);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS && status != APR_EAGAIN) {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (nghttp2_session_want_write(session->ngh2)) {
|
|
Packit |
90a5c9 |
ap_update_child_status(session->c->sbh, SERVER_BUSY_WRITE, NULL);
|
|
Packit |
90a5c9 |
status = h2_session_send(session);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
status = h2_conn_io_flush(&session->io);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR,
|
|
Packit |
90a5c9 |
H2_ERR_INTERNAL_ERROR, "writing");
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (session->have_read || session->have_written) {
|
|
Packit |
90a5c9 |
if (session->wait_us) {
|
|
Packit |
90a5c9 |
session->wait_us = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!nghttp2_session_want_write(session->ngh2)) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_NO_IO, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case H2_SESSION_ST_WAIT:
|
|
Packit |
90a5c9 |
if (session->wait_us <= 0) {
|
|
Packit |
90a5c9 |
session->wait_us = 10;
|
|
Packit |
90a5c9 |
if (h2_conn_io_flush(&session->io) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* repeating, increase timer for graceful backoff */
|
|
Packit |
90a5c9 |
session->wait_us = H2MIN(session->wait_us*2, MAX_WAIT_MICROS);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (trace) {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, c,
|
|
Packit |
90a5c9 |
"h2_session: wait for data, %ld micros",
|
|
Packit |
90a5c9 |
(long)session->wait_us);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
status = h2_mplx_out_trywait(session->mplx, session->wait_us,
|
|
Packit |
90a5c9 |
session->iowait);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
session->wait_us = 0;
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_STREAM_CHANGE, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_TIMEUP(status)) {
|
|
Packit |
90a5c9 |
/* go back to checking all inputs again */
|
|
Packit |
90a5c9 |
transit(session, "wait cycle", session->local.shutdown?
|
|
Packit |
90a5c9 |
H2_SESSION_ST_DONE : H2_SESSION_ST_BUSY);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_STATUS_IS_ECONNRESET(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ECONNABORTED(status)) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_WARNING, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03404), session,
|
|
Packit |
90a5c9 |
"waiting on conditional"));
|
|
Packit |
90a5c9 |
h2_session_shutdown(session, H2_ERR_INTERNAL_ERROR,
|
|
Packit |
90a5c9 |
"cond wait error", 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, c,
|
|
Packit |
90a5c9 |
H2_SSSN_LOG(APLOGNO(03080), session,
|
|
Packit |
90a5c9 |
"unknown state"));
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_PROTO_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!nghttp2_session_want_read(session->ngh2)
|
|
Packit |
90a5c9 |
&& !nghttp2_session_want_write(session->ngh2)) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_NGH2_DONE, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (session->reprioritize) {
|
|
Packit |
90a5c9 |
h2_mplx_reprioritize(session->mplx, stream_pri_cmp, session);
|
|
Packit |
90a5c9 |
session->reprioritize = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
out:
|
|
Packit |
90a5c9 |
if (trace) {
|
|
Packit |
90a5c9 |
ap_log_cerror( APLOG_MARK, APLOG_TRACE3, status, c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "process returns"));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((session->state != H2_SESSION_ST_DONE)
|
|
Packit |
90a5c9 |
&& (APR_STATUS_IS_EOF(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ECONNRESET(status)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ECONNABORTED(status))) {
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return (session->state == H2_SESSION_ST_DONE)? APR_EOF : APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_session_pre_close(h2_session *session, int async)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
|
|
Packit |
90a5c9 |
H2_SSSN_MSG(session, "pre_close"));
|
|
Packit |
90a5c9 |
dispatch_event(session, H2_SESSION_EV_PRE_CLOSE, 0,
|
|
Packit |
90a5c9 |
(session->state == H2_SESSION_ST_IDLE)? "timeout" : NULL);
|
|
Packit |
90a5c9 |
status = session_cleanup(session, "pre_close");
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* no one should hold a reference to this session any longer and
|
|
Packit |
90a5c9 |
* the h2_ctx was removed from the connection.
|
|
Packit |
90a5c9 |
* Take the pool (and thus all subpools etc. down now, instead of
|
|
Packit |
90a5c9 |
* during cleanup of main connection pool. */
|
|
Packit |
90a5c9 |
apr_pool_destroy(session->pool);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|