Skip to content

net: Conn.Close() does not error on double close on wasm #45423

@johanbrandhorst

Description

@johanbrandhorst

Does this issue reproduce with the latest release?

Yes

What did you do?

Tried to write a test that checks whether a net.Conn is already closed by checking that calling Close returns an error and run it on wasm. See

if runtime.GOARCH == "wasm" {
t.Skip("conn.Close does not error as expected when called multiple times on WASM")
}
for the current workaround.

What did you expect to see?

An error suggesting that the connection has already been closed, as is consistent with all other architectures tested.

What did you see instead?

No error.

Discussion

I think the offending code is here:

go/src/net/net_fake.go

Lines 110 to 115 in 5d5f779

func (fd *netFD) Close() error {
fd.closedMu.Lock()
if fd.closed {
fd.closedMu.Unlock()
return nil
}

On unix platforms the behaviour is to return internal/poll.ErrNetClosing or internal/pool.ErrFileClosing:

func (fd *FD) Close() error {
if !fd.fdmu.increfAndClose() {
return errClosing(fd.isFile)
}

func errClosing(isFile bool) error {
if isFile {
return ErrFileClosing
}
return ErrNetClosing
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-wasmWebAssembly issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions