Closed lesismal closed 2 years ago
Why remove the pointer of sync.RWMutex
.
Does this not go wrong in some cases, such as when using a shallow copy?
I only wanted to pr this commit: https://github.com/lesismal/melody/commit/e21886f3a7b601a5509274fb14dcc66d859304a8 but when I committed some new on my branch, it was auto appended to this pr by github, I just reverted the latest and leave only https://github.com/lesismal/melody/commit/e21886f3a7b601a5509274fb14dcc66d859304a8 here.
Why remove the pointer of
sync.RWMutex
. Does this not go wrong in some cases, such as when using a shallow copy?
It's not removing the pointer of sync.RWMutex
.
Plz see the 1st floor, the close() doesn't guard the process of changing the conn's state and closing the output chan, some other goroutine may push data to the output chan after the chan has been closed.
And run the testing code, you will reproduce the panic.
@lesismal The problem you are referring to does exist and you fixed it.
I only wanted to pr this commit: lesismal@e21886f but when I committed some new on my branch, it was auto appended to this pr by github, I just reverted the latest and leave only lesismal@e21886f here.
@iwctwbai here
Yes, I just happened to see your code and was a little confused @lesismal
@iwctwbai After I have made this pr, I saw this: https://github.com/olahol/melody/issues/58 , so I think this pr would not be reviewed and merged for a long time. After that I make new commit on my branch and didn't come back to see this pr again and didn't find that it was auto appended to this pr until you leave a message:joy:, thank you for your attention and review!
Hope everything is fine with olahol.
Hope everything is fine with olahol.
@lesismal Hello, I have an question about your commit content is not close output channel. it's no problem of send data to no read channel(output)?
my soluation is defer a recover func in writeMessage. however, this is not the best soluation.
Because writeMessage
use select with default
, then it won't block:
select {
case s.output <- message:
default:
s.melody.errorHandler(s, errors.New("session message buffer is full"))
}
The chan will be gc even it is not closed.
So, it's ok.
Thank you for the fix :+1: Sorry for ghosting for so long
Really happy to see u again, welcome back!
Thank you for the kind words and the help fixing this old library :slightly_smiling_face:
if two goroutines exec these two lines nearly the same time: https://github.com/olahol/melody/blob/master/session.go#L59 https://github.com/olahol/melody/blob/master/session.go#L24
the two goroutines will get the same opening state, and if
close(s.output)
exec first https://github.com/olahol/melody/blob/master/session.go#L63case s.output <- message
will panic: https://github.com/olahol/melody/blob/master/session.go#L30try this example to reproduce this bug:
then wait for enough time, we will get: