Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zmq4 publisher issue, publisher is hanging while publishing continuously on socket #114

Closed
jay11ca39 opened this issue Oct 6, 2017 · 3 comments

Comments

@jay11ca39
Copy link

jay11ca39 commented Oct 6, 2017

Hello @pebbe

Steps to reproduce the issue:

  1. copy the below code in file: sample.go

package main


import (
	zmq "github.com/pebbe/zmq4"

	"fmt"
)

var publisher *zmq.Socket
func publishRoutine() {
     for {
		 publisher.Send("Hello", 0)
		 fmt.Printf("\nEvent publisher")
    }
} 

func main() {

    var err error
    publisher, err = zmq.NewSocket(zmq.PUB)
    defer publisher.Close()
    publisher.Bind("tcp://*:5562")
    if nil != err {}

	//start a go routine to continously publish the events
    go publishRoutine()

	//blocker for main exit
	for {}
}
  1. Build the code :
    $ go build sample.go

  2. Run the sample:
    $ ./sample

Expected: It should continuously publish the events.
Actual: It is hanging after publishing some events.

@jay11ca39 jay11ca39 changed the title zmq4 publisher issue, publisher is hanging while publishing infintely zmq4 publisher issue, publisher is hanging while publishing continuously on socket Oct 6, 2017
@pebbe
Copy link
Owner

pebbe commented Oct 6, 2017

It's hanging on for {}. This has nothing to do with zmq. The empty for loop prevents Go to switch between Go routines.

@pebbe pebbe closed this as completed Oct 6, 2017
@jay11ca39
Copy link
Author

That for{} loop is for blocking for application to exit.
BTW When i tested without go routine it worked well. But is it the problem with go routine to switch between main and new thread?

@jay11ca39
Copy link
Author

Hi @pebbe ,
Instead of for{} loop i used channel to block exit of main program it worked well.
Thanks for help.

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

No branches or pull requests

2 participants