libp2p / libp2p/go-libp2p-pubsub

Running Next On A Subscription Hangs Indefinitely

Open
#183 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug
Dominant language
Go
Stars
364
Forks
221
PR merge metrics
No merged PRs in 30d

Description

I'm attempting to create a distributed task processing system using libp2p that will send a message when work has been done. Other workers are supposed to pick up on this message, and finish processing.

Currently I'm running into an issue,

I have a loop like

for {
	msg, err := subscription.Next(context.Background())
	if err != nil {
		return err
       }
      .........
}

Currently this will hang, and even when one worker sends a message to the topic, none of the other workers currently listening to the topic will receive the message. However, if I do something like this:

for {
go func() {
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	defer cancel()
	msg, err := finishedSub.Next(ctx)
	if err != nil {
		return
	}
	msg, err := subscription.Next(context.Background())
	if err != nil {
		return err
       }
      .........
}()
}

Then this works, and other workers are able to pick up on the messages. However the one flaw I can detect with this, is that at some point goroutine panics start occurring. Something seems to be off here, and that Next isn't being handled properly or my understanding of the expected functionality of Next is incorrect.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the subscription.Next(context.Background()) loop shown in the issue and compare it with the timeout-based workaround. Reproduce the behavior with multiple workers and check whether messages are received without spawning repeated goroutines or causing panics. Done means Next behaves as expected for subscribed workers, or the issue clearly documents the required context and lifecycle handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.