Compare commits

...

2 Commits

Author SHA1 Message Date
5b42030f9d Fix another "deadlock" in METADAPT-A
What fucking idiot go developer decided recv from a nil channel
locks the entire program. ?????? just have it return zero value and
false.
2025-01-28 16:14:27 -05:00
4daccca66a Fix METADAPT-A deadlock when closing transaction 2025-01-28 16:11:23 -05:00

View File

@ -104,7 +104,7 @@ func (this *a) receive() {
this.transLock.Lock() this.transLock.Lock()
defer this.transLock.Unlock() defer this.transLock.Unlock()
for _, trans := range this.transMap { for _, trans := range this.transMap {
trans.Close() trans.closeDontUnlist()
} }
clear(this.transMap) clear(this.transMap)
}() }()
@ -163,9 +163,13 @@ type transA struct {
} }
func (this *transA) Close() error { func (this *transA) Close() error {
this.incoming.Close() err := this.closeDontUnlist()
this.parent.unlistTransactionSafe(this.ID()) this.parent.unlistTransactionSafe(this.ID())
return nil return err
}
func (this *transA) closeDontUnlist() error {
return this.incoming.Close()
} }
func (this *transA) ID() int64 { func (this *transA) ID() int64 {
@ -177,15 +181,18 @@ func (this *transA) Send(method uint16, data []byte) error {
} }
func (this *transA) Receive() (method uint16, data []byte, err error) { func (this *transA) Receive() (method uint16, data []byte, err error) {
message, ok := <- this.incoming.Receive() receive := this.incoming.Receive()
if !ok { if receive != nil {
if this.parent.err == nil { if message, ok := <- receive; ok {
return 0, nil, fmt.Errorf("could not receive message: %w", io.EOF) return message.method, message.payload, nil
} else {
return 0, nil, this.parent.err
} }
} }
return message.method, message.payload, nil
if this.parent.err == nil {
return 0, nil, fmt.Errorf("could not receive message: %w", io.EOF)
} else {
return 0, nil, this.parent.err
}
} }
type incomingMessage struct { type incomingMessage struct {