-
Notifications
You must be signed in to change notification settings - Fork 335
[WPB 3796] Fix background worker for federation policy allowAll #3526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
9823fd0
a347a75
88f202f
8752761
3d4ffc1
3998753
06e2f3f
de782bf
90477ca
21c5770
ff59df1
3e2a4c3
07042e7
7265f2d
cc820b8
3252b16
a6230d3
de0cabd
1277282
883c063
f76a1c6
815d15d
ca6c633
4ce60fc
e38a6c7
cb6184c
f3440fd
15c0cef
2200da8
97856cd
d456a7c
b9afef6
eb7ee50
dc70e1c
1e7d00c
c5bb489
fddd9c9
91718c1
195c51c
878b407
24ce4f9
b244bf0
8c8da68
12d11cb
606476c
b854f6d
d716699
055f55d
abd25da
3ac378b
29e3429
b246036
d47e4df
f32375d
00fd31a
67b7b2e
2a86f02
b0f3e4d
4f246bf
4d6e6da
06e21e2
f2cf937
a6927ba
7c8bf45
975f142
5f89f96
3bbcf4d
23b7130
4c34668
5f74ad8
e65ef0b
43dd731
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [background-worker] Get federation remote domains from rabbitMQ, not from brig (this fixes a bug in federation policy `allowAll`) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ import System.Logger.Class qualified as Log | |
| import UnliftIO | ||
| import Wire.API.Federation.BackendNotifications | ||
| import Wire.API.Federation.Client | ||
| import Wire.API.Routes.FederationDomainConfig | ||
| import Wire.BackgroundWorker.Env | ||
| import Wire.BackgroundWorker.Options | ||
| import Wire.BackgroundWorker.Util | ||
|
|
@@ -123,7 +122,7 @@ startPusher consumersRef chan = do | |
| throwM e | ||
|
|
||
| -- If this thread is cancelled, catch the exception, kill the consumers, and carry on. | ||
| -- FUTUREWORK?: | ||
| -- | ||
| -- If this throws an exception on the Chan / in the forever loop, the exception will | ||
| -- bubble all the way up and kill the pod. Kubernetes should restart the pod automatically. | ||
| flip | ||
|
|
@@ -132,29 +131,15 @@ startPusher consumersRef chan = do | |
| Handler $ cleanup @SomeAsyncException | ||
| ] | ||
| $ do | ||
| -- Get an initial set of domains from the sync thread | ||
| -- The Chan that we will be waiting on isn't initialised with a | ||
| -- value until the domain update loop runs the callback for the | ||
| -- first time. | ||
| initRemotes <- liftIO $ readIORef env.remoteDomains | ||
| -- Get an initial set of consumers for the domains pulled from the IORef | ||
| -- so that we aren't just sitting around not doing anything for a bit at | ||
| -- the start. | ||
| ensureConsumers consumersRef chan $ domain <$> initRemotes.remotes | ||
| -- Wait for updates to the domains, this is where the bulk of the action | ||
| -- is going to take place | ||
| consumers <- newIORef mempty | ||
| forever $ do | ||
| -- Wait for a new set of domains. This is a blocking action | ||
| -- so we will only move past here when we get a new set of domains. | ||
| -- It is a bit nicer than having another timeout value, as Brig is | ||
| -- already providing one in the domain update message. | ||
| chanRemotes <- liftIO $ readChan env.remoteDomainsChan | ||
| -- Make new consumers for the new domains, clean up old ones from the consumer map. | ||
| ensureConsumers consumersRef chan $ domain <$> chanRemotes.remotes | ||
| remoteDomains <- getRemoteDomains | ||
| ensureConsumers consumers chan remoteDomains | ||
| threadDelay (round $ 1_000_000 * fromMaybe 60 env.backendNotificationsConfig.remotesRefreshInterval) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a |
||
|
|
||
| ensureConsumers :: IORef (Map Domain (Q.ConsumerTag, MVar ())) -> Q.Channel -> [Domain] -> AppT IO () | ||
| ensureConsumers consumers chan domains = do | ||
| keys' <- Set.fromList . Map.keys <$> readIORef consumers | ||
| keys' <- Map.keysSet <$> readIORef consumers | ||
| let domains' = Set.fromList domains | ||
| droppedDomains = Set.difference keys' domains' | ||
| -- Loop over all of the new domains. We can check for existing consumers and add new ones. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ data Opts = Opts | |
| federatorInternal :: !Endpoint, | ||
| rabbitmq :: !RabbitMqAdminOpts, | ||
| galley :: !Endpoint, | ||
| brig :: !Endpoint, | ||
| -- | Seconds, Nothing for no timeout | ||
| defederationTimeout :: Maybe Int, | ||
| backendNotificationPusher :: BackendNotificationsConfig | ||
|
|
@@ -31,7 +30,9 @@ data BackendNotificationsConfig = BackendNotificationsConfig | |
| -- | Upper limit on amount of time (in microseconds) to wait before retrying | ||
| -- any notification. This exists to ensure that exponential back-off doesn't | ||
| -- cause wait times to be very big. | ||
| pushBackoffMaxWait :: Int | ||
| pushBackoffMaxWait :: Int, | ||
| -- | Number of seconds between two calls to `getRemoteDomains`. | ||
| remotesRefreshInterval :: Maybe Double | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i get the last point, but i just think doubles are more ergonomic. anyway i'll align it with the rest. |
||
| } | ||
| deriving (Show, Generic) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no release made with this bug, so you can also just drop this changelog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.