Skip to content

netchan: closing a channel on exported end doesn't propagate to the caller #805

@gopherbot

Description

@gopherbot

by ghexsel:

I have a loop in the exporter sender side that sends 10 items then closes 
the netchan.  On the importer side, I have a loop to check if the channel 
is closed before trying to receive, but the channel doesn't appear to get 
closed.  Instead, I see the "2010/05/23 16:39:38 importer header: EOF" 
message (in the importer receiver side).  

A simple solution would be to change the sender side to consider EOF a 
close signal on importer.go#run().

Exporter relevant bits:

    for i := 0; i < count; i++ {
        if closed(ch) {
            fmt.Printf("Can't send, channel is closed\n")
            os.Exit(1)
        } else {
            ch <- value {23 + i, "hello"}
        }
    }
    close(ch)


Importer relevant bits:

    for {
        if closed(ch) {
            fmt.Printf("Can't receive, channel is closed\n")
            os.Exit(0)
        } else {
            v := <-ch
            fmt.Printf("%v\n", v)
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions