Skip to content

loopyWriter continuing to run after GracefulStop causing race with t.Log #6485

Closed
@fho

Description

@fho

Hello,

we are starting a grpc-server in a Go testserver.
On test finish we call Server.GracefulStop() via t.Cleanup().

We forward all log messages from the grpc packages to the test logger, by setting grpclog.SetLoggerV2 to a t.Log wrapper.

When we run the tests with the -race parameter, it happens from now and then that a race is detected because loopyWriter logs a message to t.Log() after the test finish.
As I understand Server.GracefulStop() does not wait until the loopyWriter go-routine has terminated.

The message that is logged after test termination from loopyWriter happens here:

l.logger.Infof("loopyWriter exiting with error: %v", err)
) maybe there are also other log calls that can happen after GracefulStop.

Is there a way to wait in a testcase until loopyWriter terminated that I'm missing?
If not, shouldn't it be possible to do a termination that ensures no go-routines are running afterwards?
This would also e.g. work well together with https://github.com/uber-go/goleak, that checks if any go-routines are leaked in a testcase.

grpc-go version: 1.57

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