Skip to content

Update addok-cluster to v0.10.0 and add graceful shutdown handler#13

Merged
jdesboeufs merged 2 commits intomasterfrom
copilot/update-addok-cluster-version
Oct 15, 2025
Merged

Update addok-cluster to v0.10.0 and add graceful shutdown handler#13
jdesboeufs merged 2 commits intomasterfrom
copilot/update-addok-cluster-version

Conversation

Copy link
Contributor

Copilot AI commented Oct 15, 2025

Overview

This PR updates the addok-cluster dependency to version 0.10.0 and implements graceful shutdown functionality using the new onTerminate callback feature.

Changes

Updated Dependencies

  • Updated addok-cluster from ^0.9.0 to ^0.10.0

Server Improvements

The server now properly handles graceful shutdown when receiving termination signals:

Added onTerminate handler:

const cluster = await createCluster({
  onTerminate(reason) {
    console.log(`Cluster terminated: ${reason}`)
    process.exit(0)
  }
})

Added signal handlers for SIGTERM and SIGINT:

async function handleShutdown(signal) {
  console.log(`Received ${signal}, gracefully shutting down...`)
  
  // Close HTTP server first
  httpServer.close(() => {
    console.log('Server closed')
  })
  
  // Then terminate the cluster
  await cluster.end()
}

process.on('SIGTERM', () => handleShutdown('SIGTERM'))
process.on('SIGINT', () => handleShutdown('SIGINT'))

Shutdown Process Flow

  1. Server receives SIGTERM or SIGINT signal
  2. HTTP server stops accepting new connections
  3. cluster.end() is called to gracefully terminate all addok worker nodes
  4. The onTerminate callback is triggered automatically by the cluster
  5. Process exits cleanly

Tests

Added new test file test/cluster.js to verify the graceful termination behavior:

  • Verifies cluster mock objects support the end() method
  • Verifies cluster properly terminates and rejects subsequent operations after termination

Benefits

  • Ensures in-flight requests are completed before shutdown
  • Properly cleans up resources (HTTP server, addok worker nodes)
  • Prevents data loss or incomplete operations during deployment or maintenance
  • Follows best practices for Node.js process lifecycle management

Testing

  • All 28 tests pass (26 existing + 2 new)
  • Linter passes with no errors
  • Maintains backward compatibility with existing functionality
Original prompt

Update to last addok-cluster version and provide a onTerminate handler to gracefully stop process.

Update related unit tests.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jdesboeufs <1231232+jdesboeufs@users.noreply.github.com>
Copilot AI changed the title [WIP] Update to latest addok-cluster version and add onTerminate handler Update addok-cluster to v0.10.0 and add graceful shutdown handler Oct 15, 2025
Copilot AI requested a review from jdesboeufs October 15, 2025 13:36
@jdesboeufs jdesboeufs marked this pull request as ready for review October 15, 2025 13:46
@jdesboeufs jdesboeufs merged commit 921a765 into master Oct 15, 2025
4 of 5 checks passed
@jdesboeufs jdesboeufs deleted the copilot/update-addok-cluster-version branch October 15, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants