Skip to content

If server closes a connection just after accepting it, the client is stuck #23

@starius

Description

@starius
package main

import (
	"log"
	"net"
	"sync"

	"github.com/inconshreveable/muxado"
)

func main() {
	a, b := net.Pipe()
	cli := muxado.Client(a, nil)
	ser := muxado.Server(b, nil)
	var wg sync.WaitGroup
	defer wg.Wait()
	wg.Add(1)
	go func() {
		defer wg.Done()
		x, err := cli.Open()
		if err != nil {
			log.Fatalf("cli.Open: %s.", err)
		}
		buf := make([]byte, 5)
		_, err = x.Read(buf)
		log.Printf("x.Read: %s.", err)
	}()
	wg.Add(1)
	go func() {
		defer wg.Done()
		y, err := ser.Accept()
		if err != nil {
			log.Fatalf("ser.Accept: %s.", err)
		}
		y.Close()
	}()
}

If a client sends something over the connection, it works as expected (client gets io.EOF).
If the connection is closed by the client rather than the server (and the server reads), it also works.

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