Commit Graph

8 Commits

Author SHA1 Message Date
Agniva De Sarker
e39569b358 MM-23805: Refactor web_hub (#14277)
* MM-23800: remove goroutineID and stack printing

Each hub has a goroutineID which is calculated with a known hack.
The FAQ clearly explains why goroutines don't have an id:
https://golang.org/doc/faq#no_goroutine_id.

We only added that because sometimes the hub would be deadlocked and
having the goroutineID would be useful when getting the stack trace.
This is also problematic in stress tests because the hubs would
frequently get overloaded and the logs would unnecessarily have stack traces.

But that was in the past, and we have done extensive testing with
load tests and fuzz testing to smooth any rough edges remaining.
Including adding additional metrics for hub buffer size.

Monitoring the metrics is a better way to approach this problem.
Therefore, we remove these kludges from the code.

* Also remove deadlock checking code

There is no need for that anymore since
we are getting rid of the stack printing anyways.

Let's do a wholesale refactor and clean up the codebase.

* MM-23805: Refactor web_hub

This is a beginning of the refactoring of the websocket code.

To start off with, we unexport some methods and constants which did not
need to be exported. There are more remaining but some are out of scope for this PR.

The main chunk of refactor is to unexport the webconn send channel
which was the main cause of panics. Since we were directly sending
to the connection from various parts of the codebase, it would be possible
that the send channel would be closed and we could still send a message.
This would crash the server.

To fix this, we refactor the code to centralize all sending from the main
hub goroutine. This means we can leverage the connections map to check
if the connection exists or not, and only then send the message.

We also move the cluster calls to cluster.go.

* bring back cluster code inside hub

* Incorporate review comments

* Address review comments

* rename index

* MM-23807: Refactor web_conn

- Unexport some struct fields and constants which are not necessary
to be accessed from outside the package. This will help us moving
the entire websocket handling code to a separate package later.

- Change some empty string checks to check for empty string rather
than doing a len check which is more idiomatic. Both of them compile
to the same code. So it doesn't make a difference performance-wise.

- Remove redundant ToJson calls to get the length.

- Incorporate review comments

- Unexport some more methods

* Fix field name

* Run make app-layers

* Add note on hub check
2020-04-23 13:16:18 +05:30
Eli Yukelzon
fb4d27d596 MM-22265 - Restrict the WS "update_team" event broadcast (#13848)
Automatic Merge
2020-02-11 03:41:55 -05:00
Claudio Costa
80dd2915db [MM-19914] Fix data races in WebSocketEvent (#13039)
* Make WebSocketEvent type immutable

* Update code to use updated immutable WebSocketEvent type

* Export WebSocketEvent fields and mark them as deprecated
2019-12-24 09:32:11 +01:00
Jesús Espino
a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00
Miguel de la Cruz
2259b7f2a8 [MM-19948] Set version on module file and internal paths (#13186)
* [MM-19948] Set version on module file and internal paths

* Fixes after merge

* Fix i18n checker error
2019-11-28 14:39:38 +01:00
Shreyansh Chouhan
39ceaa3e86 [MM-13833] Configured unit tests to log through t.Log (#10272)
* Rerouted the unit test logs through t.Log

* resolving merge confilvts

* Update testing.go

* Update helper_test.go

* Added godocs for NewTestingLogger

* Added go docs for NewTestingLogger

* Resolving conflicts
2019-02-14 13:52:11 -04:00
Jesse Hallam
a78913178c Ensure unittest isolation (#9819)
* api4: fix TestGetUsersNotInTeam assertions

This test was relying on data from a previous test run. With the data cleared before each test, the assertions much match reality.

* *testlib: always InitSystemAdmin

Some tests implicitly relied on the basic user having system
administrator privileges because it was the first user created as such.
Eliminate `InitSystemAdmin` and explicitly create the system admin user
instead to avoid this ambiguity going forward.

* *testlib: drop all tables before each test

* api4: split up TestChannelDelete to avoid duplicate InitBasic

* api4: teardown in TestResetPassword, for when this test comes back

* invalidate cache on DropAllTables

This is necessary since the test store persists across tests.

* disable parallel tests

While tests within a package must be explicitly parallelized using `t.Parallel()`, tests across packages are run in parallel by default.  This causes problems given that the tests all currently share the same database instance.

Unfortunately, this also means that running the tests is much slower, but we can return to this later.
2018-11-20 20:16:25 -05:00
Joram Wilander
283f34b9c6 MM-10007 Send an admin and regular WS events when a user is updated (#8588)
* Add user.DeepCopy() function

* Add omit admins/non-admins to WS broadcast and use for updating users

* Updates per feedback and adding unit test for ShouldSendEvent
2018-04-20 08:44:18 -04:00