Klaus Demo nginx / 030a1f9
Fixed socket inheritance on reload and binary upgrade. On nginx reload or binary upgrade, an attempt is made to inherit listen sockets from the previous configuration. Previously, no check for socket type was made and the inherited socket could have the wrong type. On binary upgrade, socket type was not detected at all. Wrong socket type could lead to errors on that socket due to different logic and unsupported syscalls. For example, a UDP socket, inherited as TCP, lead to the following error after arrival of a datagram: "accept() failed (102: Operation not supported on socket)". Roman Arutyunyan 3 years ago
2 changed file(s) with 20 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
209209
210210 olen = sizeof(int);
211211
212 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_TYPE, (void *) &ls[i].type,
213 &olen)
214 == -1)
215 {
216 ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno,
217 "getsockopt(SO_TYPE) %V failed", &ls[i].addr_text);
218 ls[i].ignore = 1;
219 continue;
220 }
221
222 olen = sizeof(int);
223
212224 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, (void *) &ls[i].rcvbuf,
213225 &olen)
214226 == -1)
272284 }
273285
274286 #endif
287
288 if (ls[i].type != SOCK_STREAM) {
289 continue;
290 }
275291
276292 #if (NGX_HAVE_TCP_FASTOPEN)
277293
511511 continue;
512512 }
513513
514 if (ls[i].type != nls[n].type) {
515 continue;
516 }
517
514518 if (ngx_cmp_sockaddr(nls[n].sockaddr, nls[n].socklen,
515519 ls[i].sockaddr, ls[i].socklen, 1)
516520 == NGX_OK)