Skip to content

fix(voice): handle negative timeouts#11362

Merged
kodiakhq[bot] merged 1 commit intodiscordjs:mainfrom
markokajzer:main
Dec 17, 2025
Merged

fix(voice): handle negative timeouts#11362
kodiakhq[bot] merged 1 commit intodiscordjs:mainfrom
markokajzer:main

Conversation

@markokajzer
Copy link
Copy Markdown
Contributor

I was getting random TimeoutNegativeWarning when running my bot with Node 24+
through --trace-warnings i was able to get the following stack trace

(node:38864) TimeoutNegativeWarning: -2 is a negative number.
Timeout duration was set to 1.
    at new Timeout (node:internal/timers:194:17)
    at setTimeout (node:timers:117:19)
    at prepareNextAudioFrame (/Users/amaterasu/projects/discord-soundbot/node_modules/@discordjs/voice/dist/index.js:137:28)
    at Immediate.<anonymous> (/Users/amaterasu/projects/discord-soundbot/node_modules/@discordjs/voice/dist/index.js:142:22)
    at process.processImmediate (node:internal/timers:504:21)

scope

explicitly handle negative timeouts during prepareNextAudioFrame

if there is a different underlying issue, let me know so i can adjust as needed 🙏

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
discord-js Skipped Skipped Dec 13, 2025 0:39am
discord-js-guide Skipped Skipped Dec 13, 2025 0:39am

@vercel vercel bot temporarily deployed to Preview – discord-js-guide December 13, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js December 13, 2025 12:39 Inactive
@Jiralite Jiralite added this to the voice 0.20.0 milestone Dec 13, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 13, 2025

📝 Walkthrough

Walkthrough

A single-line modification to the audio scheduling logic in the voice package clamps the delay for the next audio cycle to a minimum of 1 millisecond using Math.max, preventing zero or negative delay values during frame preparation.

Changes

Cohort / File(s) Summary
Audio frame scheduling fix
packages/voice/src/DataStore.ts
Added Math.max(1, ...) to clamp minimum audio cycle delay to 1 millisecond in prepareNextAudioFrame method when nextPlayer is absent and nextTime is set

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the Math.max(1, ...) wrapper correctly clamps delay values and doesn't inadvertently affect other timing calculations
  • Confirm the 1-millisecond minimum threshold is appropriate for the audio scheduling use case and doesn't cause unintended timing side effects

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(voice): handle negative timeouts' directly and specifically describes the main change: adding logic to handle negative timeout values in the voice module.
Description check ✅ Passed The description is directly related to the changeset, providing context about the TimeoutNegativeWarning issue, stack trace evidence, and the specific scope of handling negative timeouts in prepareNextAudioFrame.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4fc79a and f6a206e.

📒 Files selected for processing (1)
  • packages/voice/src/DataStore.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.43%. Comparing base (c4fc79a) to head (f6a206e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11362   +/-   ##
=======================================
  Coverage   32.43%   32.43%           
=======================================
  Files         369      369           
  Lines       13616    13616           
  Branches     1068     1068           
=======================================
  Hits         4416     4416           
  Misses       9065     9065           
  Partials      135      135           
Flag Coverage Δ
voice 55.53% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@herocmd
Copy link
Copy Markdown

herocmd commented Dec 13, 2025

@discord-js-bot pack this

@github-project-automation github-project-automation bot moved this from Todo to Review Approved in discord.js Dec 17, 2025
@kodiakhq kodiakhq bot merged commit 5f93fbd into discordjs:main Dec 17, 2025
26 checks passed
@github-project-automation github-project-automation bot moved this from Review Approved to Done in discord.js Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants