Skip to content

netease: song_url_v1 returns 502 TLS disconnect on rapid sequential requests #11

@fivood

Description

@fivood

Steps to reproduce

  1. Clone repo, npm install, npm run build
  2. node dist/cli.js dev --netease --query "ambient focus instrumental"
  3. The TUI starts but immediately fails during ensureCandidates()

Expected

NetEase search results are resolved to playable URLs, TUI starts playback.

Actual

[ERR] {
  status: 502,
  body: {
    code: 502,
    msg: 'Client network socket disconnected before secure TLS connection was established'
  },
  cookie: []
}

Root cause

The ensureCandidates() method in netease-tui-adapter.ts calls songUrl() (via song_url_v1) for each search result in a tight loop. The first 1-2 calls fail with a 502 TLS disconnect because the NetEase server drops keep-alive connections from the preceding cloudsearch call. Isolated calls succeed; only rapid sequential calls trigger the issue.

Suggested fix

Two changes:

  1. netease-tui-adapter.ts ensureCandidates() — add ~800ms delay between songUrl() calls
  2. netease-adapter.ts — add a retry helper for 502 / socket-disconnect errors (retry up to 2x with 1s delay), applied to both search() and songUrl()

These two changes make dev --netease work reliably on Windows + Node v24.14.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions