Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atp concurrency improvements #92

Merged
merged 14 commits into from
Jul 9, 2024
24 changes: 18 additions & 6 deletions atp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"sync"
"time"
)

// RunATPServer runs an ArcaflowTransportProtocol server with a given schema.
Expand Down Expand Up @@ -83,12 +84,23 @@ func initializeATPServerSession(

func (s *atpServerSession) sendRuntimeMessage(msgID uint32, runID string, message any) error {
s.encoderMutex.Lock()
defer s.encoderMutex.Unlock()
return s.cborStdout.Encode(RuntimeMessage{
MessageID: msgID,
RunID: runID,
MessageData: message,
})
doneChannel := make(chan error, 1)
go func() {
defer close(doneChannel)
doneChannel <- s.cborStdout.Encode(RuntimeMessage{
MessageID: msgID,
RunID: runID,
MessageData: message,
})
}()
select {
case err := <-doneChannel:
s.encoderMutex.Unlock()
return err
case <-time.After(time.Second * 60):
s.encoderMutex.Unlock()
return fmt.Errorf("send timeout exceeded while sending message ID %q for run id %q", msgID, runID)
}
}
webbnh marked this conversation as resolved.
Show resolved Hide resolved

func (s *atpServerSession) handleClosure() []*ServerError {
Expand Down