Skip to content

Harden MultiprocessingWriter shutdown and error handling #230

Description

@bednar

Context

PR #217 removed the generated OpenAPI write stack and introduced the internal RestClient. PR #222 refactored MultiprocessingWriter.

The current multiprocessing implementation still has shutdown and error-handling risks that can cause inconsistent state or a blocked queue.join().

Scope

Improve MultiprocessingWriter reliability:

  • Replace the assert used for runtime state validation with an explicit exception.
  • Always call queue.task_done() when processing a queued write, including failure paths.
  • Add an explicit, idempotent close() method.
  • Use close() from the context manager and keep __del__ as best-effort cleanup only.
  • Ensure on_shutdown is called at most once.
  • Handle queue timeout and worker shutdown deterministically.

Tests

Add tests covering:

  • writing before start();
  • writing after shutdown;
  • worker timeout;
  • write failure without a queue.join() deadlock;
  • repeated close() calls;
  • callback invocation count.

Acceptance criteria

  • A failed worker write cannot leave queue.join() blocked indefinitely.
  • on_shutdown is invoked at most once.
  • Shutdown is deterministic for both explicit close() and context-manager usage.
  • Existing multiprocessing behavior remains compatible.
  • All unit and integration tests pass.

Out of scope

  • Removing multiprocessing support.
  • Redesigning batching or retry behavior.
  • Adding new InfluxDB endpoints.
  • Changes to the public client API beyond the lifecycle and error-handling fixes required here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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