After registering the conn in the hub, we proceeded to send a direct message to the user. We had changed it to send the direct message in the same hub goroutine that handles the registration. This was the correct behavior and fixes chances of having panics due to sending to closed channels. However, often fixing something unearths some deeper underlying bug. This was such a case :) The issue was that register channel had a buffer size of 1. And we were sending a direct message after registration. In the code to send direct message, we were checking if the user has been registered or not, and if not, then skip it. Therefore, since the register channel buffer was 1, it could very well be that the select case would pick up the direct message send case first - in which case it would not have been registered, and therefore no hello message would be sent. The fix is to unbuffer the register and unregister channels. There does not seem to be a valid reason to make these buffered channels. They are meant to be synchronous operations, because the code following them assumes that the user has been registered. While here, we also remove all the time.Sleeps before waiting on the Response channel because they are not required at all. Waiting on a channel is already blocking. Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
9.7 KiB
9.7 KiB