Skip to content

ToBinding crashes on null service handle during unsubscribe/shutdown #1148

@hubyrod

Description

@hubyrod

Summary

ToBinding.SkipRuntime_ServiceDefinition__unsubscribe and SkipRuntime_ServiceDefinition__shutdown in @skipruntime/core crash with a TypeError when this.handles.get(skservice) returns undefined.

Additionally, abortFork() can throw inside a catch block, swallowing the original exception.

Location

@skipruntime/coredist/src/index.js, class ToBinding (around line 792+)

How to reproduce

  1. Start a Skip service with a Postgres external service
  2. Trigger a scenario where the service handle is cleaned up before unsubscribe or shutdown is called (e.g. a connection error or rapid restart)
  3. The runtime crashes with TypeError: Cannot read properties of undefined (reading 'unsubscribe') or (reading 'shutdown')

For the abortFork issue:

  1. Trigger a fork initialization failure (e.g. the external service errors during subscribe)
  2. The catch block calls this.abortFork() which itself throws
  3. The original error is lost; only the cleanup error propagates

Expected behavior

  • unsubscribe should be a no-op if the service handle no longer exists
  • shutdown should resolve gracefully if the service handle no longer exists
  • abortFork() failures during error cleanup should not mask the original exception

Workaround

// unsubscribe — add null guard
SkipRuntime_ServiceDefinition__unsubscribe(skservice, external, instance) {
    const service = this.handles.get(skservice);
    if (service == null) return;
    service.unsubscribe(external, instance);
}

// shutdown — add null guard, return resolved promise
SkipRuntime_ServiceDefinition__shutdown(skservice) {
    const service = this.handles.get(skservice);
    if (service == null) return this.handles.register(Promise.resolve());
    return this.handles.register(service.shutdown());
}

// abortFork — wrap in try-catch
catch (ex) {
    this.setFork(uuid);
    try { this.abortFork(); } catch (_) { /* cleanup failure, ignore */ }
    throw ex;
}

Version

@skipruntime/core@0.0.19

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions