Skip to content

Fix duration enforcement, JSON payload encoding, and error handling in workers#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-timer-stopping-issue
Draft

Fix duration enforcement, JSON payload encoding, and error handling in workers#1
Copilot wants to merge 2 commits intomainfrom
copilot/fix-timer-stopping-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 13, 2026

Workers continued running past the configured duration because in-flight requests were awaited (not cancelled) at the deadline. Additionally, --json always crashed at runtime due to a broken .encode() call on a parsed dict, and worker crashes silently hung the parent process forever.

Root causes & fixes

  • Timer not enforced: After the scheduler deadline, asyncio.gather(*pending) waited for all in-flight requests — up to timeout seconds past duration. Fixed by cancelling all pending tasks before gathering:

    # before
    await asyncio.gather(*pending, return_exceptions=True)
    
    # after
    for task in pending:
        task.cancel()
    await asyncio.gather(*pending, return_exceptions=True)
  • --json always crashed: json.loads(args.json).encode() called .encode() on a dict, raising AttributeError. Fixed with jsonlib.dumps(jsonlib.loads(args.json)).encode() — validates then re-serialises to bytes.

  • Unbounded catch-up burst: When the event loop stalled briefly, next_fire += interval without a bound caused a burst of accumulated missed requests. Capped by resetting next_fire = now + interval when it falls more than one interval behind.

  • Worker crash hangs parent: An unhandled exception in bootstrap_worker exited the process without putting anything in the queue, leaving q.get() blocked forever. Added a top-level except Exception in bootstrap_worker that always enqueues an error sentinel.

  • q.get() had no timeout: Added a generous timeout (duration + request_timeout + 60 s) with a queue.Empty warning, preventing indefinite hangs even if the sentinel is somehow missed.

  • No KeyboardInterrupt handling: Ctrl+C left daemon processes running and printed no report. Wrapped the collection loop to catch interrupts, terminate workers cleanly, and still emit a partial report if data was collected.


💡 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: KidiXDev <100352770+KidiXDev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix timer not stopping after set duration Fix duration enforcement, JSON payload encoding, and error handling in workers Mar 13, 2026
Copilot AI requested a review from KidiXDev March 13, 2026 03:51
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