Skip to content

port already allocated #1790

Open
Open
@saiwl

Description

@saiwl

We met "port already allocated" problem in our docker environment. It always happened after docker-daemon restarts abnormally or machine restarts abnormally.
I read the related code, and found a possible bug about this.
In the source code, the process of creating a container using port mapping is like below:

  1. create container
  2. create sandbox
  3. create endpoint
  4. allocate ports
  5. update driver endpoint store
  6. join sandbox
  7. update sandbox store

And the restore process after the daemon restarts is like below:

  1. restore port mapping based on driver endpoint restore
  2. clean up sandbox based on sandbox store
  3. clean up endpoint based on endpoint store

In the creating process, if the docker daemon or the machine restarts abnormally between step 5 and step 7 which truely happened in our environment, after docker daemon restarts, the port mapping would be restored in step 1 of restore process and will not be released in step 2 of restore process because sandbox was not updated, which causing ports leak.

I have made a simple fix which has been tested in our environment. I will make a PR later. Looking forward to your suggestions!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions