Skip to content

Add custom pre-shutdown verification for service activity #537

@mg-dev25

Description

@mg-dev25

Problem Statement

Currently, Sablier determines service activity solely based on incoming HTTP requests through the configured middleware. When the timeout period expires, services are automatically shut down without any additional checks.

This creates limitations for services that maintain active connections through other protocols (like WebSockets) but aren't receiving regular HTTP traffic. Examples include BitTorrent clients, IDE servers like code-server, development environments, and any application with long-lived connections.

Feature Request

I propose adding a configurable "pre-shutdown verification" feature that would:

  1. When a service is about to time out (session expiration)
  2. Send a custom HTTP request to a specified endpoint (could be the service itself or another service)
  3. Apply a configured condition to the response (status code, regex pattern on response body, etc.)
  4. Based on the result, either proceed with shutdown or extend the service lifetime

Use Cases

  • BitTorrent clients: Check if active downloads are in progress before shutdown
  • Code-server: Check if active editing sessions exist
  • Development environments: Check for active processes before termination
  • CI/CD pipelines: Check if builds are still running
  • Media streaming services: Check if streams are active

Implementation Approach

The feature could be implemented with minimal changes to the existing codebase:

  1. Add configuration options in Sablier's config schema:
sessions:
  verification:
    enabled: true
    endpoint: "http://service-name:port/activity-check"
    method: "GET"  # HTTP method to use
    headers:       # Optional headers to include
      Authorization: "Bearer token"
    success_codes: [200]  # HTTP status codes that indicate activity
    pattern: "active: true"  # Optional regex to apply to response body
    extension: 5m  # How long to extend session if verification passes
  1. Modify the session expiration handler to:

    • Check if verification is enabled
    • Send the configured request
    • Evaluate response against configured conditions
    • Only proceed with shutdown if verification fails
  2. Add logging for verification steps to aid debugging

Contribution Offer

I'm willing to help develop this feature!. I could start by implementing a basic version of this feature that supports HTTP status code checking, and then expand it to support regex pattern matching on response bodies.

Additional Thoughts

This approach is more efficient than continuous monitoring of WebSockets, as it only performs checks when a service is about to be shut down, minimizing overhead while still providing the desired functionality.

The verification endpoint could be a simple health check endpoint that services can implement to indicate whether they're still actively being used, giving services fine-grained control over their lifecycle without requiring Sablier to understand specific application protocols.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions