Skip to content

Commit

Permalink
fix: Quick fix for intro message race condition (#2376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Leblow authored Mar 20, 2024
1 parent ff3cbb0 commit d4f7449
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ export class StorageService extends EventEmitter {
)
const channel = this.channels.get(channelId)

this.logger(`Found existing channel: ${channel}`)
this.logger('Found existing channel:', channel)

if (channel === undefined) {
await this.channels.put(channelId, { ...channelData })
Expand Down
5 changes: 5 additions & 0 deletions packages/desktop/src/rtl-tests/community.join.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { AnyAction } from 'redux'
import {
InvitationData,
ChannelsReplicatedPayload,
ChannelSubscribedPayload,
Community,
ErrorPayload,
type NetworkInfo,
Expand Down Expand Up @@ -116,6 +117,9 @@ describe('User', () => {
},
},
})
socket.socketClient.emit<ChannelSubscribedPayload>(SocketActionTypes.CHANNEL_SUBSCRIBED, {
channelId: 'general',
})
}
}

Expand Down Expand Up @@ -184,6 +188,7 @@ describe('User', () => {
"Network/addInitializedCommunity",
"Communities/clearInvitationCodes",
"PublicChannels/channelsReplicated",
"PublicChannels/setChannelSubscribed",
"PublicChannels/addChannel",
"Messages/addPublicChannelsMessagesBase",
"PublicChannels/sendIntroductionMessage",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { put, select, call } from 'typed-redux-saga'
import { put, select, call, delay } from 'typed-redux-saga'
import { messagesActions } from '../../messages/messages.slice'
import { publicChannelsSelectors } from '../publicChannels.selectors'
import { WriteMessagePayload, MessageType, PublicChannel, PublicChannelStorage } from '@quiet/types'
Expand All @@ -24,6 +24,24 @@ export function* sendIntroductionMessageSaga(): Generator {
channelId: generalChannel.id,
}

// FIXME: This is a quick fix for an issue that can be fixed by
// unifying CHANNELS_STORED and CHANNELS_SUBSCRIBED events and
// refactoring a bit. The problem is that the frontend sends a
// message upon receiving the CHANNELS_STORED event, but the channel
// hasn't been fully initialized/subscribed yet (it doesn't exist in
// publicChannelsRepos on the backend so the backend fails to send
// it). Ideally, I think we should only tell the frontend about
// channels once they've been fully initialized. Once we fix that,
// we can remove the following code.
while (true) {
const subscribedChannels = yield* select(publicChannelsSelectors.subscribedChannels)
if (subscribedChannels.includes(generalChannel.id)) {
break
}
console.error('Failed to send introduction message, general channel not subscribed. Retrying...')
yield* delay(500)
}

yield* put(messagesActions.sendMessage(payload))
yield* put(identityActions.updateIdentity({ ...identity, introMessageSent: true }))
}

0 comments on commit d4f7449

Please sign in to comment.