AlistGo/alist · info

receive failed

Error message

receive failed

What it means

'receive failed' is returned by (*Http).Receive in internal/message/http.go when a non-blocking receive on the Received channel finds no message. The select falls through to default, signaling 'nothing to read right now' rather than an actual fault.

Solutions

  1. Prefer WaitReceive(d) to block for up to d seconds instead of busy-checking Receive()
  2. Ensure only one goroutine consumes HttpInstance.Received to avoid stealing messages
  3. If using Receive() as a probe, treat the error as 'empty', not as a failure worth logging
  4. Verify the sending side (HTTP handler writing to Received) is actually being reached

Example fix

// before
msg, err := message.HttpInstance.Receive()

// after
msg, err := message.HttpInstance.WaitReceive(10)
Defensive patterns

Strategy: fallback

Validate before calling

// probe with non-blocking Receive only when emptiness is expected
// otherwise go straight to WaitReceive

Type guard

func isReceiveFailed(err error) bool {
    return err != nil && err.Error() == "receive failed"
}

Try / catch

msg, err := message.HttpInstance.Receive()
if isReceiveFailed(err) { msg = "" /* empty poll */ }

Prevention

When it happens

Trigger: Calling HttpInstance.Receive() when no client has pushed a message into the Received channel (the endpoint that feeds it has not been called), or when a previously sent message was already consumed by another receiver.

Common situations: Polling loops that call Receive as a status check instead of using WaitReceive with a timeout; two consumers racing where one drains the only message; frontend disconnected so no inbound messages arrive.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/cc0dd50cc6517557. Report an issue: GitHub.

Appendix: source

Thrown at internal/message/http.go:57

		common.ErrorStrResp(c, "nowhere needed", 500)
	}
}

func (p *Http) Send(message Message) error {
	select {
	case p.ToSend <- message:
		return nil
	default:
		return errors.New("send failed")
	}
}

func (p *Http) Receive() (string, error) {
	select {
	case message := <-p.Received:
		return message, nil
	default:
		return "", errors.New("receive failed")
	}
}

func (p *Http) WaitSend(message Message, d int) error {
	select {
	case p.ToSend <- message:
		return nil
	case <-time.After(time.Duration(d) * time.Second):
		return errors.New("send timeout")
	}
}

func (p *Http) WaitReceive(d int) (string, error) {
	select {
	case message := <-p.Received:
		return message, nil
	case <-time.After(time.Duration(d) * time.Second):
		return "", errors.New("receive timeout")

View on GitHub (pinned to 843d9dc814)