Skip to content

Commit 283c095

Browse files
committed
fix race condition
1 parent 6f2f711 commit 283c095

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

mods/server/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (svr *httpd) Router() *gin.Engine {
236236
svr.log.Infof("MQTT websocket handler enabled")
237237
}
238238
if svr.tqlLoader != nil {
239-
svr.memoryFs = &MemoryFS{Prefix: "/web/api/tql-assets/"}
239+
svr.memoryFs = NewMemoryFS("/web/api/tql-assets/")
240240
go svr.memoryFs.Start()
241241
svr.tqlLoader.SetVolatileAssetsProvider(svr.memoryFs)
242242
group.GET("/api/tql-assets/*path", gin.WrapH(http.FileServer(svr.memoryFs)))

mods/server/http_assets.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,17 @@ type MemoryFS struct {
171171
stop chan bool
172172
}
173173

174+
func NewMemoryFS(prefix string) *MemoryFS {
175+
return &MemoryFS{
176+
Prefix: prefix,
177+
list: map[string]*MemoryFile{},
178+
stop: make(chan bool),
179+
}
180+
}
181+
174182
var _ tql.VolatileAssetsProvider = (*MemoryFS)(nil)
175183

176184
func (fs *MemoryFS) Start() {
177-
fs.stop = make(chan bool)
178-
fs.list = map[string]*MemoryFile{}
179185
ticker := time.NewTicker(30 * time.Second)
180186
defer ticker.Stop()
181187

0 commit comments

Comments
 (0)