Skip to content

runtime/debug: SetGCPercent(-1) doesn't wait for concurrent GC #22443

@aclements

Description

@aclements

Several runtime tests use SetGCPercent(-1) to disable GC because they're about to do something that interferes with preemption (sigh, #10958). However, now that SetGCPercent no longer forces a full GC, it also doesn't force a currently running concurrent GC to terminate. This results in the following possible situation:

  1. Concurrent GC starts. Sweep termination runs and we enter concurrent mark.
  2. Test calls SetGCPercent(-1).
  3. Test enters a non-preemptible loop.
  4. Concurrent GC tries to STW to enter mark termination, but can't preempt the loop, so the test deadlocks.

This can be reproduced pretty quickly by running cd runtime; go test -c; GOGC=5 stress -p 1 ./runtime.test -test.short.

Since the point of SetGCPercent(-1) is to disabled GC, it should probably want for any concurrent GC cycle to finish.

/cc @RLH

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions