From 32cdfc3db442009676b67f2df0923241823ba0e7 Mon Sep 17 00:00:00 2001 From: atavism Date: Mon, 12 Aug 2024 08:40:31 -0700 Subject: [PATCH] lock masquerade during json.Marshal --- masquerade.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/masquerade.go b/masquerade.go index 0abade8..8bfd6bf 100644 --- a/masquerade.go +++ b/masquerade.go @@ -1,6 +1,7 @@ package fronted import ( + "encoding/json" "fmt" "hash/crc32" "net" @@ -48,6 +49,18 @@ type masquerade struct { mx sync.RWMutex } +func (m *masquerade) MarshalJSON() ([]byte, error) { + m.mx.RLock() + defer m.mx.RUnlock() + // Type alias for masquerade + type Alias masquerade + return json.Marshal(&struct { + *Alias + }{ + Alias: (*Alias)(m), + }) +} + func (m *masquerade) lastSucceeded() time.Time { m.mx.RLock() defer m.mx.RUnlock()