1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

fixed race+allocation in copySrcSubProcFunc

This commit is contained in:
postmannen 2022-06-22 05:03:11 +02:00
parent 9c6ede458a
commit c6013a2968
3 changed files with 9 additions and 2 deletions

View file

@ -124,7 +124,10 @@ type process struct {
// values for a process.
func newProcess(ctx context.Context, server *server, subject Subject, processKind processKind, procFunc func() error) process {
// create the initial configuration for a sessions communicating with 1 host process.
server.processes.mu.Lock()
server.processes.lastProcessID++
pid := server.processes.lastProcessID
server.processes.mu.Unlock()
ctx, cancel := context.WithCancel(ctx)
@ -135,7 +138,7 @@ func newProcess(ctx context.Context, server *server, subject Subject, processKin
messageID: 0,
subject: subject,
node: Node(server.configuration.NodeName),
processID: server.processes.lastProcessID,
processID: pid,
processKind: processKind,
methodsAvailable: method.GetMethodsAvailable(),
toRingbufferCh: server.toRingBufferCh,

View file

@ -12,6 +12,8 @@ import (
// processes holds all the information about running processes
type processes struct {
// mutex for processes
mu sync.Mutex
// The main context for subscriber processes.
ctx context.Context
// cancel func to send cancel signal to the subscriber processes context.

View file

@ -416,7 +416,9 @@ func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.Cancel
status = copySrcDone
}
lastReadChunk = b[:n]
lastReadChunk = make([]byte, len(b[:n]))
copy(lastReadChunk, b[:n])
//lastReadChunk = b[:n]
// Create a hash of the bytes.
hash := sha256.Sum256(b[:n])