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. 22
      pkg/sesswatch/sesswatch.go

@ -88,7 +88,7 @@ archives:
- submodules/**/*
release:
draft: true
# draft: true
# 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

@ -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
## 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.

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

@ -18,15 +18,17 @@ type sesswatch struct {
}
// 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{}}
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 {
func() {
record := <-sessionsToWatch
select {
case record := <-sessionsToWatch:
// normal way to start watching a session
id := record.SessionID
pid := record.SessionPID
s.mutex.Lock()
@ -36,6 +38,18 @@ func (s *sesswatch) waiter(sessionsToWatch chan records.Record) {
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