Skip to content

Commit

Permalink
try lock
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Dec 31, 2023
1 parent b96c3b0 commit f7bddba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,12 @@ func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error
_ = c.conn.SetWriteDeadline(deadline)
if len(buf1) == 0 {
resultCh := make(chan iouring.Result, 1)
ringLock.Lock()
if _, errSubmit := ring.SubmitRequest(iouring.Write(int(c.connFD), buf0), resultCh); errSubmit != nil {
ringLock.Unlock()
err = errSubmit
} else {
ringLock.Unlock()
res := <-resultCh
err = res.Err()
}
Expand Down
2 changes: 2 additions & 0 deletions internal/websocket/uring.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net"
"sync"
"syscall"

"github.com/centrifugal/centrifuge/internal/iouring-go"
Expand All @@ -17,6 +18,7 @@ func initIoUring() *iouring.IOURing {
return ring
}

var ringLock sync.Mutex
var ring = initIoUring()

func extractConnFd(conn net.Conn) (uintptr, error) {
Expand Down

0 comments on commit f7bddba

Please sign in to comment.