Skip to content

Feature: Add force parameter to close method for immediate shutdown #294

Closed

Description

@coderabbitai

Feature Request

Add a force parameter to the server's close() method to allow immediate shutdown that forcefully terminates in-flight requests.

Motivation

Currently, in-flight requests can potentially keep the server alive indefinitely during shutdown. While this may not be an issue in environments like Serverpod Cloud (where containers are force-terminated after a timeout), having a force parameter would make the API more complete and give users better control over shutdown behavior.

Proposed Solution

Add a force parameter (default: false) to the close() method that:

  • When false (default): Waits for in-flight requests to complete (current behavior)
  • When true: Immediately closes the server and forcefully terminates remaining connections

This approach allows users to implement their own timeout logic if needed:

// Example: Close with a 30-second timeout
Future.any([
  server.close(),
  Future.delayed(Duration(seconds: 30)).then((_) => server.close(force: true))
]);

Use Case

This is particularly useful for:

  • Self-hosted deployments where container orchestration behavior may vary
  • Scenarios where long-running requests should not delay server shutdown indefinitely
  • Production environments requiring predictable shutdown timing
  • Custom timeout implementations based on specific application needs

Context

This enhancement was suggested during testing of graceful shutdown behavior in PR #292, which verified that in-flight requests complete successfully during shutdown.

Related

Activity

  1. added
    area: configuration
    area: runtime
    enhancement
    on Dec 19, 2025
  2. SandPod commented on Dec 19, 2025

    @SandPod
    Contributor

    This would already be supported if we add a force parameter to the close method. Then the user could simply add a timeout for the close future that then calls close(force: true).

  3. SandPod commented on Dec 19, 2025

    @SandPod
    Contributor

    @coderabbitai - Please update this feature request so that it request a force parameter to the close method instead as suggested by the comment above.

  4. moved this from Inbox 📫 to Backlog 🗂️ in Serverpod Frameworkson Dec 19, 2025
  5. changed the title [-]Feature: Add configurable timeout for graceful shutdown[/-] [+]Feature: Add force parameter to close method for immediate shutdown[/+] on Dec 19, 2025
  6. coderabbitai commented on Dec 19, 2025

    @coderabbitai
    ContributorAuthor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    # Fetch the details of issue #294 to see the current description
    gh issue view 294 --json title,body,number
    

    Length of output: 1473


    🏁 Script executed:

    #!/bin/bash
    # Update the issue title and body to reflect the force parameter approach
    gh issue edit 294 \
      --title "Feature: Add force parameter to close method for immediate shutdown" \
      --body "## Feature Request
    
    Add a \`force\` parameter to the server's \`close()\` method to allow immediate shutdown that forcefully terminates in-flight requests.
    
    ## Motivation
    
    Currently, in-flight requests can potentially keep the server alive indefinitely during shutdown. While this may not be an issue in environments like Serverpod Cloud (where containers are force-terminated after a timeout), having a \`force\` parameter would make the API more complete and give users better control over shutdown behavior.
    
    ## Proposed Solution
    
    Add a \`force\` parameter (default: \`false\`) to the \`close()\` method that:
    - When \`false\` (default): Waits for in-flight requests to complete (current behavior)
    - When \`true\`: Immediately closes the server and forcefully terminates remaining connections
    
    This approach allows users to implement their own timeout logic if needed:
    \`\`\`dart
    // Example: Close with a 30-second timeout
    Future.any([
      server.close(),
      Future.delayed(Duration(seconds: 30)).then((_) => server.close(force: true))
    ]);
    \`\`\`
    
    ## Use Case
    
    This is particularly useful for:
    - Self-hosted deployments where container orchestration behavior may vary
    - Scenarios where long-running requests should not delay server shutdown indefinitely
    - Production environments requiring predictable shutdown timing
    - Custom timeout implementations based on specific application needs
    
    ## Context
    
    This enhancement was suggested during testing of graceful shutdown behavior in PR #292, which verified that in-flight requests complete successfully during shutdown.
    
    ## Related
    
    - PR: https://github.com/serverpod/relic/pull/292
    - Requested by: @nielsenko"
    
    echo "Issue #294 has been updated successfully"
    

    Length of output: 86


    @SandPod, I've successfully updated issue #294 to request a force parameter for the close() method instead of a configurable timeout parameter.

    Changes made:

    • Title: Changed to "Feature: Add force parameter to close method for immediate shutdown"
    • Description: Updated to propose a force parameter (default: false) that allows immediate shutdown when set to true
    • Example: Added a code example showing how users can implement their own timeout logic by combining Future.any with close(force: true)

    The updated approach gives users more flexibility to implement custom timeout behavior while keeping the API simpler. You can view the updated issue here: #294

  7. moved this from Backlog 🗂️ to Done 🚀 in Serverpod Frameworkson Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: configurationarea: runtimeenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions