fix potential memory leak, don't draft when releasing

pull/58/head v2.4.4
Simon Let 6 years ago
parent 94899ef5d2
commit d92e07c073
  1. 2
      .goreleaser.yml
  2. 1
      README.md
  3. 6
      cmd/daemon/run-server.go
  4. 38
      pkg/sesswatch/sesswatch.go

@ -88,7 +88,7 @@ archives:
- submodules/**/* - submodules/**/*
release: release:
draft: true # draft: true
# If set to auto, will mark the release as not ready for production # If set to auto, will mark the release as not ready for production
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1 # in case there is an indicator for this in the tag e.g. v1.0.0-rc1

@ -67,7 +67,6 @@ Imagine being able to search your shell history based on both the command itself
- :heavy_check_mark: Provide a tool to sanitize the recorded history - :heavy_check_mark: Provide a tool to sanitize the recorded history
## Data sanitization and analysis ## Data sanitization and analysis
In order to be able to develop a good history tool I will need to get some insight into real life shell and shell history usage patterns. In order to be able to develop a good history tool I will need to get some insight into real life shell and shell history usage patterns.

@ -49,9 +49,11 @@ func runServer(config cfg.Config, reshHistoryPath, bashHistoryPath, zshHistoryPa
config.SesshistInitHistorySize) config.SesshistInitHistorySize)
// sesswatch // sesswatch
sesswatchRecords := make(chan records.Record)
recordSubscribers = append(recordSubscribers, sesswatchRecords)
sesswatchSessionsToWatch := make(chan records.Record) sesswatchSessionsToWatch := make(chan records.Record)
sessionInitSubscribers = append(sessionInitSubscribers, sesswatchSessionsToWatch) sessionInitSubscribers = append(sessionInitSubscribers, sesswatchRecords, sesswatchSessionsToWatch)
sesswatch.Go(sesswatchSessionsToWatch, sessionDropSubscribers, config.SesswatchPeriodSeconds) sesswatch.Go(sesswatchSessionsToWatch, sesswatchRecords, sessionDropSubscribers, config.SesswatchPeriodSeconds)
// handlers // handlers
mux := http.NewServeMux() mux := http.NewServeMux()

@ -18,23 +18,37 @@ type sesswatch struct {
} }
// Go runs the session watcher - watches sessions and sends // Go runs the session watcher - watches sessions and sends
func Go(sessionsToWatch chan records.Record, sessionsToDrop []chan string, sleepSeconds uint) { func Go(sessionsToWatch chan records.Record, sessionsToWatchRecords chan records.Record, sessionsToDrop []chan string, sleepSeconds uint) {
sw := sesswatch{sessionsToDrop: sessionsToDrop, sleepSeconds: sleepSeconds, watchedSessions: map[string]bool{}} sw := sesswatch{sessionsToDrop: sessionsToDrop, sleepSeconds: sleepSeconds, watchedSessions: map[string]bool{}}
go sw.waiter(sessionsToWatch) go sw.waiter(sessionsToWatch, sessionsToWatchRecords)
} }
func (s *sesswatch) waiter(sessionsToWatch chan records.Record) { func (s *sesswatch) waiter(sessionsToWatch chan records.Record, sessionsToWatchRecords chan records.Record) {
for { for {
func() { func() {
record := <-sessionsToWatch select {
id := record.SessionID case record := <-sessionsToWatch:
pid := record.SessionPID // normal way to start watching a session
s.mutex.Lock() id := record.SessionID
defer s.mutex.Unlock() pid := record.SessionPID
if s.watchedSessions[id] == false { s.mutex.Lock()
log.Println("sesswatch: start watching NEW session ~ pid:", id, "~", pid) defer s.mutex.Unlock()
s.watchedSessions[id] = true if s.watchedSessions[id] == false {
go s.watcher(id, pid) log.Println("sesswatch: start watching NEW session ~ pid:", id, "~", pid)
s.watchedSessions[id] = true
go s.watcher(id, pid)
}
case record := <-sessionsToWatchRecords:
// additional safety - watch sessions that were never properly initialized
id := record.SessionID
pid := record.SessionPID
s.mutex.Lock()
defer s.mutex.Unlock()
if s.watchedSessions[id] == false {
log.Println("sesswatch WARN: start watching NEW session (based on /record) ~ pid:", id, "~", pid)
s.watchedSessions[id] = true
go s.watcher(id, pid)
}
} }
}() }()
} }

Loading…
Cancel
Save