Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

pidfile lock waiting broken in docker containers #1261

@vektah

Description

@vektah

Pids in docker containers always start at one. So if you run dep inside a docker container as part of a script the pids are very likely to collide between different containers.

The cache lock in source_manager.go uses the pid to detect and avoid a deadlock where the process is waiting for itself.

Unfortunately this all results in a false positive abort when running in docker.

Steps to reproduce

Given directory containing Dockerfile

FROM golang:1.9.1

RUN go get -u github.com/golang/dep/cmd/dep

RUN mkdir /go/src/test
WORKDIR /go/src/test
ADD main.go .
RUN dep init

and main.go

package main

import _ "github.com/go-chi/chi"

func main() {}

run

docker build . -t test
mkdir cache
(docker run -v $PWD/cache:/go/pkg/dep test dep ensure -v &) && \
    docker run -v $PWD/cache:/go/pkg/dep test dep ensure -v 

expected output

One process would get the lock, the other would wait:

Gopkg.lock was already in sync with imports and Gopkg.toml
(1/1) Wrote github.com/go-chi/chi@v3.3.0
Gopkg.lock was already in sync with imports and Gopkg.toml
(1/1) Wrote github.com/go-chi/chi@v3.3.0

actual output

Gopkg.lock was already in sync with imports and Gopkg.toml
lockfile /go/pkg/dep/sm.lock already locked by this process
(1/1) Wrote github.com/go-chi/chi@v3.3.0

Proposed solution

The deadlock detection is useful, but perhaps the process could track it own state? If dep knows it isnt holding the lock but the lock file exists with our pid wait like normal.

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