mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-20 22:52:13 +00:00
fixed race+allocation in copySrcSubProcFunc
This commit is contained in:
parent
9c6ede458a
commit
c6013a2968
3 changed files with 9 additions and 2 deletions
|
@ -124,7 +124,10 @@ type process struct {
|
||||||
// values for a process.
|
// values for a process.
|
||||||
func newProcess(ctx context.Context, server *server, subject Subject, processKind processKind, procFunc func() error) 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.
|
// create the initial configuration for a sessions communicating with 1 host process.
|
||||||
|
server.processes.mu.Lock()
|
||||||
server.processes.lastProcessID++
|
server.processes.lastProcessID++
|
||||||
|
pid := server.processes.lastProcessID
|
||||||
|
server.processes.mu.Unlock()
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
|
@ -135,7 +138,7 @@ func newProcess(ctx context.Context, server *server, subject Subject, processKin
|
||||||
messageID: 0,
|
messageID: 0,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
node: Node(server.configuration.NodeName),
|
node: Node(server.configuration.NodeName),
|
||||||
processID: server.processes.lastProcessID,
|
processID: pid,
|
||||||
processKind: processKind,
|
processKind: processKind,
|
||||||
methodsAvailable: method.GetMethodsAvailable(),
|
methodsAvailable: method.GetMethodsAvailable(),
|
||||||
toRingbufferCh: server.toRingBufferCh,
|
toRingbufferCh: server.toRingBufferCh,
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
|
|
||||||
// processes holds all the information about running processes
|
// processes holds all the information about running processes
|
||||||
type processes struct {
|
type processes struct {
|
||||||
|
// mutex for processes
|
||||||
|
mu sync.Mutex
|
||||||
// The main context for subscriber processes.
|
// The main context for subscriber processes.
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
// cancel func to send cancel signal to the subscriber processes context.
|
// cancel func to send cancel signal to the subscriber processes context.
|
||||||
|
|
|
@ -416,7 +416,9 @@ func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.Cancel
|
||||||
status = copySrcDone
|
status = copySrcDone
|
||||||
}
|
}
|
||||||
|
|
||||||
lastReadChunk = b[:n]
|
lastReadChunk = make([]byte, len(b[:n]))
|
||||||
|
copy(lastReadChunk, b[:n])
|
||||||
|
//lastReadChunk = b[:n]
|
||||||
|
|
||||||
// Create a hash of the bytes.
|
// Create a hash of the bytes.
|
||||||
hash := sha256.Sum256(b[:n])
|
hash := sha256.Sum256(b[:n])
|
||||||
|
|
Loading…
Add table
Reference in a new issue