Port collisions in tests—when multiple tests spin up servers and accidentally pick the same port—are a common source of flakiness. Random port selection reduces but doesn't eliminate collisions, and sequential port incrementing creates its own problems. The reliable solution is binding to port 0, which asks the OS kernel to
Table of contents
Can we pick a random port?Incremental ports?Sooooo ephemeral ports from the kernel?Sort: