Skip to content

Commit

Permalink
fix: 🐛 sync reciverChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
onionj committed Feb 16, 2024
1 parent 3d3c79b commit 4b7872f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion muxr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Client) Start() error {
switch typ {
case TYPE_DATA:
if stream, ok := c.streamsManager.Get(id); ok {
go func(stream *Stream) {
func(stream *Stream) {
stream.Lock()
defer stream.Unlock()
if !stream.isClosed {
Expand Down
4 changes: 3 additions & 1 deletion muxr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func wsServerHandler(writer http.ResponseWriter, request *http.Request) {

typ, lenght, id := ParseHeader(data[:NUM_BYTES_HEADER])

fmt.Println(string(data[NUM_BYTES_HEADER:]))

switch typ {
case TYPE_INITIAL:
stream := newStream(id, connAdaptor)
Expand All @@ -100,7 +102,7 @@ func wsServerHandler(writer http.ResponseWriter, request *http.Request) {
case TYPE_DATA:
stream, ok := streamsManager.Get(id)
if ok {
go func() {
func() {
stream.Lock()
defer stream.Unlock()
if !stream.isClosed {
Expand Down
8 changes: 1 addition & 7 deletions muxr/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newStream(
) *Stream {
return &Stream{
id: id,
reciverChannel: make(chan []byte),
reciverChannel: make(chan []byte, 100), // TODO, replace this channel with a queue
isClosed: false,
connAdaptor: connAdaptor,
}
Expand Down Expand Up @@ -57,12 +57,6 @@ func (st *Stream) Close() {

func (st *Stream) Kill() {

// Clear the channel
select {
case <-st.reciverChannel:
default:
}

st.Lock()
defer st.Unlock()

Expand Down

0 comments on commit 4b7872f

Please sign in to comment.