Skip to content

Commit

Permalink
Merge pull request #41 from getlantern/atavism/cache-updates
Browse files Browse the repository at this point in the history
Lock masquerade object during json.Marshal
  • Loading branch information
atavism authored Aug 12, 2024
2 parents 9369ca3 + 318e336 commit d549c37
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions masquerade.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fronted

import (
"encoding/json"
"fmt"
"hash/crc32"
"net"
Expand Down Expand Up @@ -48,6 +49,15 @@ type masquerade struct {
mx sync.RWMutex
}

// MarshalJSON marshals masquerade into json
func (m *masquerade) MarshalJSON() ([]byte, error) {
m.mx.RLock()
defer m.mx.RUnlock()
// Type alias for masquerade so that we don't infinitely recurse when marshaling the struct
type alias masquerade
return json.Marshal((*alias)(m))
}

func (m *masquerade) lastSucceeded() time.Time {
m.mx.RLock()
defer m.mx.RUnlock()
Expand Down

0 comments on commit d549c37

Please sign in to comment.