Fix oom-killer JSON cache cleanup

This commit is contained in:
世界
2026-11-26 23:53:53 +08:00
parent 463c44e7f9
commit 99f20dda88
2 changed files with 33 additions and 2 deletions
+10 -2
View File
@@ -1,4 +1,4 @@
//go:build badlinkname
//go:build badlinkname && !goexperiment.jsonv2
package oomkiller
@@ -7,13 +7,21 @@ import (
_ "unsafe"
)
//go:linkname jsonFieldCache json.fieldCache
//go:linkname jsonEncoderCache encoding/json.encoderCache
var jsonEncoderCache sync.Map
//go:linkname jsonFieldCache encoding/json.fieldCache
var jsonFieldCache sync.Map
//go:linkname contextJSONEncoderCache github.com/sagernet/sing/common/json/internal/contextjson.encoderCache
var contextJSONEncoderCache sync.Map
//go:linkname contextJSONFieldCache github.com/sagernet/sing/common/json/internal/contextjson.fieldCache
var contextJSONFieldCache sync.Map
func badCleanup() {
jsonEncoderCache.Clear()
jsonFieldCache.Clear()
contextJSONEncoderCache.Clear()
contextJSONFieldCache.Clear()
}
+23
View File
@@ -0,0 +1,23 @@
//go:build badlinkname && goexperiment.jsonv2
package oomkiller
import (
"sync"
_ "unsafe"
)
//go:linkname jsonArshalerCache encoding/json/v2.lookupArshalerCache
var jsonArshalerCache sync.Map
//go:linkname contextJSONEncoderCache github.com/sagernet/sing/common/json/internal/contextjson.encoderCache
var contextJSONEncoderCache sync.Map
//go:linkname contextJSONFieldCache github.com/sagernet/sing/common/json/internal/contextjson.fieldCache
var contextJSONFieldCache sync.Map
func badCleanup() {
jsonArshalerCache.Clear()
contextJSONEncoderCache.Clear()
contextJSONFieldCache.Clear()
}