{"id":1306,"date":"2026-10-05T22:37:24","date_gmt":"2026-10-05T22:37:24","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1306"},"modified":"2026-10-05T22:37:24","modified_gmt":"2026-10-05T22:37:24","slug":"zero-downtime-service-reloads-connection-draining-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/","title":{"rendered":"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Restarting a web server or proxy on a busy VPS is not the same as reloading it. A naive <code>systemctl restart<\/code> tears the listening socket down and drops every connection in flight &mdash; a burst of 502s that lasts just long enough to be noticed, and long enough to lose writes on an API. This article covers the mechanisms that let you swap a binary or reload a config without severing established connections, and how to verify the drain actually worked.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understand who owns the listening socket<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The behaviour you get on restart depends entirely on whether the service master process survives. With nginx, <code>SIGHUP<\/code> tells the master to re-read configuration and start fresh worker processes while the old workers finish their current requests. The listening socket is inherited, so no connection is refused. With <code>systemctl restart<\/code> the whole process group dies, and every socket goes with it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># graceful config reload - no dropped connections\nnginx -s reload\n\n# binary upgrade without losing the socket\nsystemctl reload nginx\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The distinction matters most on a small, single-vCPU instance where the drain window has no spare core to hide behind: every millisecond a worker spends finishing is a millisecond the new workers are crowded.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the drain, do not assume it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After a reload, old workers enter the &#8220;shutting down&#8221; state and linger until their keepalive connections time out or finish. You can observe this directly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># old and new workers coexist during the drain\nps -eo pid,ppid,stat,cmd | grep '[n]ginx: worker'\n\n# count ESTABLISHED connections per worker\nss -tnp | grep nginx | awk '{print $6}' | sort | uniq -c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A worker that refuses to exit usually means long-lived upstream connections or an idle keepalive client holding it open. Cap how long a worker is allowed to linger with <code>worker_shutdown_timeout<\/code> &mdash; without it, a slow client can pin an old worker (and its memory) far longer than you expect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># in the http block\nworker_shutdown_timeout 30s;\nkeepalive_timeout 15s;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">SO_REUSEPORT for independent worker restarts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An alternative to the master\/worker model is <code>SO_REUSEPORT<\/code>, which lets multiple independent processes bind the same port and have the kernel load-balance incoming connections across them. Each listener has its own accept queue, so you can retire one process while another keeps serving:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># verify the kernel allows it (it is a sysctl, default on modern kernels)\nsysctl net.ipv4.ip_unprivileged_port_start\ncat \/proc\/sys\/net\/core\/somaxconn\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The tradeoff is fairness: the kernel hashes connections to sockets, and a burst can land unevenly across processes. On a small VPS the master\/worker reload model is usually simpler and more predictable. Reach for <code>SO_REUSEPORT<\/code> when you need genuinely independent processes &mdash; blue\/green binary swaps, or a second binary listening during migration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SIGQUIT, SIGTERM and graceful shutdown<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Signals are not interchangeable. For nginx, <code>SIGQUIT<\/code> means graceful shutdown, <code>SIGTERM<\/code> means fast shutdown (immediate), and <code>SIGHUP<\/code> means reload. Sending the wrong one during a maintenance window is a common cause of &#8220;the reload dropped traffic&#8221;. Confirm the semantics for your own daemon before scripting it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># graceful stop of the master: finish in-flight work, then exit\nkill -QUIT $(cat \/run\/nginx.pid)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For application servers the pattern differs, but the principle is constant: there is usually a signal or a management endpoint that transitions the process to &#8220;stop accepting, finish current work&#8221;, and a harsher one that kills immediately. Use the former for deploys and the latter only for unresponsive processes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Draining behind a load balancer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If your VPS sits behind a balancer, the drain must happen at two layers. Marking the backend unhealthy before reloading prevents new connections from arriving, and waiting for the balancer&#8217;s own detection interval before stopping means in-flight requests complete. A health check that only tests TCP lets connections reach a process mid-shutdown &mdash; use an application-level readiness endpoint that starts failing the moment a drain begins.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prove it with a load generator<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Do not trust the theory. Run continuous requests against the service while you reload it, and check for any non-2xx response. A simple loop with <code>curl<\/code> is enough to catch a dropped connection on a low-traffic site:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i in $(seq 1 5000); do\n  code=$(curl -s -o \/dev\/null -w '%{http_code}' http:\/\/127.0.0.1\/health)\n  [ \"$code\" = \"200\" ] || echo \"FAIL $i: $code\"\ndone\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run this in one terminal and trigger the reload in another. Any <code>FAIL<\/code> line is a real dropped request. After you have confirmed a clean drain, you can deploy with confidence on the same <a href=\"https:\/\/virtualserversvps.com\/\">premium cloud solutions<\/a> stack that keeps a predictable baseline. Graceful reloads are the rare optimisation that costs nothing but attention &mdash; and a well-behaved daemon on a properly configured <a href=\"https:\/\/virtualserversvps.com\/\">virtual server<\/a> will drain every connection before it exits.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to reload web services on a VPS without dropping connections: nginx SIGHUP semantics, worker_shutdown_timeout draining, SO_REUSEPORT, and a curl loop that proves zero failed requests.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1306","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"How to reload web services on a VPS without dropping connections: nginx SIGHUP semantics, worker_shutdown_timeout draining, SO_REUSEPORT, and a curl loop that proves zero failed requests.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics\" \/>\n<meta property=\"og:description\" content=\"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T22:37:24+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/\",\"name\":\"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-10-05T22:37:24+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"How to reload web services on a VPS without dropping connections: nginx SIGHUP semantics, worker_shutdown_timeout draining, SO_REUSEPORT, and a curl loop that proves zero failed requests.\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics - Virtual Servers VPS Blog","description":"How to reload web services on a VPS without dropping connections: nginx SIGHUP semantics, worker_shutdown_timeout draining, SO_REUSEPORT, and a curl loop that proves zero failed requests.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/","og_locale":"en_US","og_type":"article","og_title":"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics","og_description":"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics","og_url":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-10-05T22:37:24+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/","url":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/","name":"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-10-05T22:37:24+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"How to reload web services on a VPS without dropping connections: nginx SIGHUP semantics, worker_shutdown_timeout draining, SO_REUSEPORT, and a curl loop that proves zero failed requests.","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/zero-downtime-service-reloads-connection-draining-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Zero-Downtime Service Reloads on a VPS: Connection Draining, SO_REUSEPORT and SIGQUIT Semantics"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1306"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1306\/revisions"}],"predecessor-version":[{"id":1309,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1306\/revisions\/1309"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}