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

Listeners with same name will cause panic. #8

Open
sbilly opened this issue Dec 15, 2019 · 1 comment
Open

Listeners with same name will cause panic. #8

sbilly opened this issue Dec 15, 2019 · 1 comment

Comments

@sbilly
Copy link

sbilly commented Dec 15, 2019

Listener with same name will cause panic.

Hello, world.panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10e8f62]

goroutine 1 [running]:
github.com/akutz/memconn.(*Listener).Close(0x0, 0x0, 0x7)
        /.go/src/github.com/akutz/memconn/memconn_listener.go:95 +0x22
main.main()
        /temp/memconn.go:48 +0x2c7
exit status 2

Source Code:

package main

import (
	"io"
	"os"

	"github.com/akutz/memconn"
)

// ExampleBuffered illustrates a server and client that
// communicate over a buffered, in-memory connection.
func main() {
	// Announce a new listener named "localhost" on MemConn's
	// buffered network, "memb".
	lis, _ := memconn.Listen("memb", "localhost")
	lis2, _ := memconn.Listen("memb", "localhost")

	// Ensure the listener is closed.
	defer lis.Close()
	defer lis2.Close()

	// Start a goroutine that will wait for a client to dial the
	// listener and then echo back any data sent to the remote
	// connection.
	go func() {
		conn, _ := lis.Accept()

		// If no errors occur then make sure the connection is closed.
		defer conn.Close()

		// Echo the data back to the client.
		io.CopyN(conn, conn, 13)
	}()

	// Dial the buffered, in-memory network named "localhost".
	conn, _ := memconn.Dial("memb", "localhost")

	// Ensure the connection is closed.
	defer conn.Close()

	// Write the data to the server.
	conn.Write([]byte("Hello, world."))

	// Read the data from the server.
	io.CopyN(os.Stdout, conn, 13)

	// Output: Hello, world.
}
@jan4984
Copy link

jan4984 commented Sep 14, 2020

panic or ?

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