Skip to content

Commit 6ce7661

Browse files
authored
fix: potential panic in Server.GetTasks() (#55)
Keep the mutex locked while copying task names.
1 parent 42e9432 commit 6ce7661

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

server.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,11 @@ func NewServer(o ServerOpts) (*Server, error) {
146146
// GetTasks() returns a list of all tasks registered with the server.
147147
func (s *Server) GetTasks() []string {
148148
s.p.RLock()
149-
tasks := s.tasks
150-
s.p.RUnlock()
149+
defer s.p.RUnlock()
151150

152-
var (
153-
t = make([]string, len(tasks))
154-
i = 0
155-
)
156-
for k := range tasks {
157-
t[i] = k
158-
i++
151+
t := make([]string, 0, len(s.tasks))
152+
for name := range s.tasks {
153+
t = append(t, name)
159154
}
160155

161156
return t

0 commit comments

Comments
 (0)