mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix race on state serialization
Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
This commit is contained in:
parent
93d6adf8a1
commit
f1975cbc7c
1 changed files with 11 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -49,6 +50,16 @@ func (s *State) String() string {
|
||||||
return fmt.Sprintf("Exited (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
|
return fmt.Sprintf("Exited (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type jState State
|
||||||
|
|
||||||
|
// MarshalJSON for state is needed to avoid race conditions on inspect
|
||||||
|
func (s *State) MarshalJSON() ([]byte, error) {
|
||||||
|
s.RLock()
|
||||||
|
b, err := json.Marshal(jState(*s))
|
||||||
|
s.RUnlock()
|
||||||
|
return b, err
|
||||||
|
}
|
||||||
|
|
||||||
func wait(waitChan <-chan struct{}, timeout time.Duration) error {
|
func wait(waitChan <-chan struct{}, timeout time.Duration) error {
|
||||||
if timeout < 0 {
|
if timeout < 0 {
|
||||||
<-waitChan
|
<-waitChan
|
||||||
|
|
Loading…
Add table
Reference in a new issue