Skip to content

cmd/vet: Add check for channels that must be buffered #9399

@titanous

Description

@titanous

There are at least two places in the standard library where channels must have a non-zero buffer in order for the program to be correct:

  1. os.Signal channels passed to signal.Notify.
  2. *rpc.Call channels passed to Client.Go in net/rpc.

I propose a vet check that ensures that these channels are buffered.

I took a quick look at @rsc's pubgo dataset (circa early 2013), and in the code that compiles, I found 161 calls to make(chan os.Signal) of which 61 were unbuffered. I do not have a newer dataset handy (is there one?) but I think it's reasonable to guess that the ratio in newer code would not have changed significantly.

I currently have a vet check written that ensures that all calls to make(os.Signal) have a non-zero buffer, but this check seems a bit too simplistic, as there may be uses for these channels that do not require a buffer. I think it's safer to require buffered channels to be passed into the mentioned calls. However, I'm not familiar enough with the relevant packages to understand what the best approach for this is.

This was originally discussed on the mailing list.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions