42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.66k stars 618 forks source link

Buffer empty after stream disconnects #2170

Open merthsoft opened 3 months ago

merthsoft commented 3 months ago

Describe the bug A clear and concise description of what the bug is.

After streaming from the api/stream endpoint, messages do not appear in api/messages buffer.

To Reproduce Steps to reproduce the behavior:

Connect a stream to api/stream Send a message Disconnect from stream Send another message Read from api/messages

Expected behavior A clear and concise description of what you expected to happen.

I would expect messages that came in after the stream was disconnected to go into the buffer.

Screenshots/debug logs If applicable, add screenshots to help explain your problem. Use logs from running matterbridge -debug if possible.

Log from above repro steps with a message a sent twice, once before and once after disconnecting the stream.

[0000]  INFO main:         [setupLogger:matterbridge.go:104] Enabling debug logging.
[0000]  INFO main:         [main:matterbridge.go:44] Running version 1.26.0 6dafebc7
[0000]  INFO router:       [Start:gateway/router.go:66] Parsing gateway test
[0000]  INFO router:       [Start:gateway/router.go:75] Starting bridge: discord.merthbotdev
[0000]  INFO api:          [func4:bridge/api/api.go:89] Listening on 127.0.0.1:4243
[0000]  INFO api:          [func4:bridge/api/api.go:89] Listening on 127.0.0.1:4242
[0000]  INFO discord:      [Connect:bridge/discord/discord.go:70] Connecting
[0000]  INFO discord:      [Connect:bridge/discord/discord.go:83] Connection succeeded
[0001] DEBUG discord:      [AddWebhook:bridge/discord/transmitter/transmitter.go:113] Manually added webhook "1264605176723931336" to channel "724000672793755670"
[0001]  INFO discord:      [joinChannels:bridge/bridge.go:77] discord.merthbotdev: joining ID:724000672793755670 (ID: ID:724000672793755670discord.merthbotdev)
[0001]  INFO router:       [Start:gateway/router.go:75] Starting bridge: api.bot
[0001]  INFO api:          [joinChannels:bridge/bridge.go:77] api.bot: joining api (ID: apiapi.bot)
[0001]  INFO router:       [Start:gateway/router.go:75] Starting bridge: api.test
[0001]  INFO api:          [joinChannels:bridge/bridge.go:77] api.test: joining api (ID: apiapi.test)
[0001]  INFO main:         [main:matterbridge.go:68] Gateway(s) started succesfully. Now relaying messages
[0013] DEBUG discord:      [messageCreate:bridge/discord/handlers.go:110] == Receiving event &discordgo.Message{ID:"1267902266648825907", ChannelID:"724000672793755670", GuildID:"724000672122667169", Content:"a", Timestamp:time.Date(2024, time.July, 30, 17, 50, 56, 854000000, time.Location("")), EditedTimestamp:<nil>, MentionRoles:[]string{}, TTS:false, MentionEveryone:false, Author:(*discordgo.User)(0xc000840540), Attachments:[]*discordgo.MessageAttachment{}, Components:[]discordgo.MessageComponent{}, Embeds:[]*discordgo.MessageEmbed{}, Mentions:[]*discordgo.User{}, Reactions:[]*discordgo.MessageReactions(nil), Pinned:false, Type:0, WebhookID:"", Member:(*discordgo.Member)(0xc0005861b0), MentionChannels:[]*discordgo.Channel(nil), Activity:(*discordgo.MessageActivity)(nil), Application:(*discordgo.MessageApplication)(nil), MessageReference:(*discordgo.MessageReference)(nil), ReferencedMessage:(*discordgo.Message)(nil), Interaction:(*discordgo.MessageInteraction)(nil), Flags:0, Thread:(*discordgo.Channel)(nil), StickerItems:[]*discordgo.Sticker(nil)}
[0013] DEBUG discord:      [messageCreate:bridge/discord/handlers.go:161] <= Sending message from merthsoft on discord.merthbotdev to gateway
[0013] DEBUG discord:      [messageCreate:bridge/discord/handlers.go:162] <= Message is config.Message{Text:"a", Channel:"ID:724000672793755670", Username:"merthsoft", UserID:"127620798423760896", Avatar:"https://cdn.discordapp.com/avatars/127620798423760896/180fb06393e8a8eb9d0488d1be2c0ce3.jpg", Account:"discord.merthbotdev", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), ID:"1267902266648825907", Extra:map[string][]interface {}(nil)}
[0013] DEBUG gateway:      [SendMessage:gateway/gateway.go:499] => Sending config.Message{Text:"a", Channel:"ID:724000672793755670", Username:"merthsoft", UserID:"127620798423760896", Avatar:"https://cdn.discordapp.com/avatars/127620798423760896/180fb06393e8a8eb9d0488d1be2c0ce3.jpg", Account:"discord.merthbotdev", Event:"", Protocol:"discord", Gateway:"test", ParentID:"", Timestamp:time.Date(2024, time.July, 30, 13, 50, 57, 19888100, time.Local), ID:"1267902266648825907", Extra:map[string][]interface {}(nil)} from discord.merthbotdev (ID:724000672793755670) to api.bot (api)
[0013] DEBUG api:          [Send:bridge/api/api.go:114] enqueueing message from [D] <merthsoft>  on ring buffer
[0013] DEBUG gateway:      [func1:gateway/gateway.go:508] => Send from discord.merthbotdev (ID:724000672793755670) to api.bot (api) took 0s
[0013] DEBUG gateway:      [SendMessage:gateway/gateway.go:499] => Sending config.Message{Text:"a", Channel:"ID:724000672793755670", Username:"merthsoft", UserID:"127620798423760896", Avatar:"https://cdn.discordapp.com/avatars/127620798423760896/180fb06393e8a8eb9d0488d1be2c0ce3.jpg", Account:"discord.merthbotdev", Event:"", Protocol:"discord", Gateway:"test", ParentID:"", Timestamp:time.Date(2024, time.July, 30, 13, 50, 57, 19888100, time.Local), ID:"1267902266648825907", Extra:map[string][]interface {}(nil)} from discord.merthbotdev (ID:724000672793755670) to api.test (api)
[0013] DEBUG api:          [Send:bridge/api/api.go:114] enqueueing message from [D] <merthsoft>  on ring buffer
[0013] DEBUG gateway:      [func1:gateway/gateway.go:508] => Send from discord.merthbotdev (ID:724000672793755670) to api.test (api) took 0s
[0021] DEBUG discord:      [messageCreate:bridge/discord/handlers.go:110] == Receiving event &discordgo.Message{ID:"1267902300723089483", ChannelID:"724000672793755670", GuildID:"724000672122667169", Content:"a", Timestamp:time.Date(2024, time.July, 30, 17, 51, 4, 978000000, time.Location("")), EditedTimestamp:<nil>, MentionRoles:[]string{}, TTS:false, MentionEveryone:false, Author:(*discordgo.User)(0xc000840600), Attachments:[]*discordgo.MessageAttachment{}, Components:[]discordgo.MessageComponent{}, Embeds:[]*discordgo.MessageEmbed{}, Mentions:[]*discordgo.User{}, Reactions:[]*discordgo.MessageReactions(nil), Pinned:false, Type:0, WebhookID:"", Member:(*discordgo.Member)(0xc0005863f0), MentionChannels:[]*discordgo.Channel(nil), Activity:(*discordgo.MessageActivity)(nil), Application:(*discordgo.MessageApplication)(nil), MessageReference:(*discordgo.MessageReference)(nil), ReferencedMessage:(*discordgo.Message)(nil), Interaction:(*discordgo.MessageInteraction)(nil), Flags:0, Thread:(*discordgo.Channel)(nil), StickerItems:[]*discordgo.Sticker(nil)}
[0021] DEBUG discord:      [messageCreate:bridge/discord/handlers.go:161] <= Sending message from merthsoft on discord.merthbotdev to gateway
[0021] DEBUG discord:      [messageCreate:bridge/discord/handlers.go:162] <= Message is config.Message{Text:"a", Channel:"ID:724000672793755670", Username:"merthsoft", UserID:"127620798423760896", Avatar:"https://cdn.discordapp.com/avatars/127620798423760896/180fb06393e8a8eb9d0488d1be2c0ce3.jpg", Account:"discord.merthbotdev", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), ID:"1267902300723089483", Extra:map[string][]interface {}(nil)}
[0021] DEBUG gateway:      [SendMessage:gateway/gateway.go:499] => Sending config.Message{Text:"a", Channel:"ID:724000672793755670", Username:"merthsoft", UserID:"127620798423760896", Avatar:"https://cdn.discordapp.com/avatars/127620798423760896/180fb06393e8a8eb9d0488d1be2c0ce3.jpg", Account:"discord.merthbotdev", Event:"", Protocol:"discord", Gateway:"test", ParentID:"", Timestamp:time.Date(2024, time.July, 30, 13, 51, 5, 203333300, time.Local), ID:"1267902300723089483", Extra:map[string][]interface {}(nil)} from discord.merthbotdev (ID:724000672793755670) to api.bot (api)
[0021] DEBUG api:          [Send:bridge/api/api.go:114] enqueueing message from [D] <merthsoft>  on ring buffer
[0021] DEBUG gateway:      [func1:gateway/gateway.go:508] => Send from discord.merthbotdev (ID:724000672793755670) to api.bot (api) took 35.2µs
[0021] DEBUG gateway:      [SendMessage:gateway/gateway.go:499] => Sending config.Message{Text:"a", Channel:"ID:724000672793755670", Username:"merthsoft", UserID:"127620798423760896", Avatar:"https://cdn.discordapp.com/avatars/127620798423760896/180fb06393e8a8eb9d0488d1be2c0ce3.jpg", Account:"discord.merthbotdev", Event:"", Protocol:"discord", Gateway:"test", ParentID:"", Timestamp:time.Date(2024, time.July, 30, 13, 51, 5, 203333300, time.Local), ID:"1267902300723089483", Extra:map[string][]interface {}(nil)} from discord.merthbotdev (ID:724000672793755670) to api.test (api)
[0021] DEBUG api:          [Send:bridge/api/api.go:114] enqueueing message from [D] <merthsoft>  on ring buffer
[0021] DEBUG gateway:      [func1:gateway/gateway.go:508] => Send from discord.merthbotdev (ID:724000672793755670) to api.test (api) took 0s

Environment (please complete the following information):

Windows 10, version: 1.26.0 6dafebc7

Additional context Please add your configuration file (be sure to exclude or anonymize private data (tokens/passwords))

[general]
RemoteNickFormat="[{LABEL}] <{NICK}> "

[discord]
[discord.merthbotdev]
Label="D"
Token="redacted"
Server="724000672122667169"
RemoteNickFormat="{NICK} ({PROTOCOL})"
AllowMention=["users"]

[api.bot]
BindAddress = "127.0.0.1:4242"
Buffer = 10
Label = "#"

[api.test]
BindAddress = "127.0.0.1:4243"
Buffer = 10
Label = "#"

[[gateway]]
name="test"
enable=true
    [[gateway.inout]]
    account = "api.bot"
    channel = "test"

    [[gateway.inout]]
    account = "api.test"
    channel = "test"

    [[gateway.inout]]
    account="discord.merthbotdev"
    channel="ID:724000672793755670"
        [gateway.inout.options]
        WebhookURL="https://discord.com/api/webhooks/1264605176723931336/redacted"