annotate src/event/quic/ngx_event_quic_socket.h @ 9204:631ee3c6d38c

Upstream: fixed usage of closed sockets with filter finalization. When filter finalization is triggered when working with an upstream server, and error_page redirects request processing to some simple handler, ngx_http_request_finalize() triggers request termination when the response is sent. In particular, via the upstream cleanup handler, nginx will close the upstream connection and the corresponding socket. Still, this can happen to be with ngx_event_pipe() on stack. While the code will set p->downstream_error due to NGX_ERROR returned from the output filter chain by filter finalization, otherwise the error will be ignored till control returns to ngx_http_upstream_process_request(). And event pipe might try reading from the (already closed) socket, resulting in "readv() failed (9: Bad file descriptor) while reading upstream" errors (or even segfaults with SSL). Such errors were seen with the following configuration: location /t2 { proxy_pass http://127.0.0.1:8080/big; image_filter_buffer 10m; image_filter resize 150 100; error_page 415 = /empty; } location /empty { return 204; } location /big { # big enough static file } Fix is to clear p->upstream in ngx_http_upstream_finalize_request(), and ensure that p->upstream is checked in ngx_event_pipe_read_upstream() and when handling events at ngx_event_pipe() exit.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 30 Jan 2024 03:20:10 +0300
parents c389200e10a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8763
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
2 /*
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
3 * Copyright (C) Nginx, Inc.
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
4 */
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
5
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
6
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
7 #ifndef _NGX_EVENT_QUIC_SOCKET_H_INCLUDED_
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
8 #define _NGX_EVENT_QUIC_SOCKET_H_INCLUDED_
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
9
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
10
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
11 #include <ngx_config.h>
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
12 #include <ngx_core.h>
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
13
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
14
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
15 ngx_int_t ngx_quic_open_sockets(ngx_connection_t *c,
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
16 ngx_quic_connection_t *qc, ngx_quic_header_t *pkt);
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
17 void ngx_quic_close_sockets(ngx_connection_t *c);
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
18
8955
32daba3aabb2 QUIC: got rid of ngx_quic_create_temp_socket().
Vladimir Homutov <vl@nginx.com>
parents: 8911
diff changeset
19 ngx_quic_socket_t *ngx_quic_create_socket(ngx_connection_t *c,
8763
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
20 ngx_quic_connection_t *qc);
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
21 ngx_int_t ngx_quic_listen(ngx_connection_t *c, ngx_quic_connection_t *qc,
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
22 ngx_quic_socket_t *qsock);
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
23 void ngx_quic_close_socket(ngx_connection_t *c, ngx_quic_socket_t *qsock);
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
24
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
25 ngx_quic_socket_t *ngx_quic_find_socket(ngx_connection_t *c, uint64_t seqnum);
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
26
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
27
4117aa7fa38e QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
28 #endif /* _NGX_EVENT_QUIC_SOCKET_H_INCLUDED_ */