Skip to content
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

DBus connection terminates inside the Flatpak runtime #220

Closed
MMarco94 opened this issue Jun 19, 2023 · 12 comments
Closed

DBus connection terminates inside the Flatpak runtime #220

MMarco94 opened this issue Jun 19, 2023 · 12 comments

Comments

@MMarco94
Copy link

Hello, I'm using this library to communicate with the DBus to implement the MPRIS protocol.

Everything works in a "normal" environment (thanks BTW for making it possible), however everything starts to break down when running the app inside the Flatpak runtime.

In particular, my issue is that the Flatpak DBus proxy (xdg-dbus-proxy) closes the DBus connection after a few message exchanges with the error Invalid client serial (which is raised here).

My guess is that some message got sent (or received?) out of order, and xdg-dbus-proxy detects something strange with the serials and will close the connection.
To test my hypothesis, I tried to reduce the thread count of your library:

...
withSignalThreadCount(1)
withErrorHandlerThreadCount(1)
withMethodCallThreadCount(1)
withMethodReturnThreadCount(1)
...

Surprisingly, this helped: now the connection stays open for a bit longer, but it still gets closed after a while with the same error.


Is there a way to make this library use a single thread for all operations?

@MMarco94
Copy link
Author

I forgot: this is the log before the crash.

2023-06-19 23:49:44.084 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Creating message with serial 13
2023-06-19 23:49:44.084 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: yyyy data: 108, 4, 0, 1
2023-06-19 23:49:44.084 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: ua(yv) data: 14, [[1, [o, /org/mpris/MediaPlayer2]], [2, [s, org.freedesktop.DBus.Properties]], [3, [s, PropertiesChanged]], [8, [g, sa{sv}as]]]
2023-06-19 23:49:44.085 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: sa{sv}as data: org.mpris.MediaPlayer2.Player, {PlaybackStatus=[Paused], LoopStatus=[Playlist], Metadata=[{mpris:trackid=[/io/github/MMarco94/music-player/-997585971], mpris:length=[234031020], xesam:artist=[[ABBA]], xesam:albumArtist=[[ABBA]], xesam:album=[Arrival], xesam:title=[My Love, My Life], xesam:discNumber=[3], mpris:artUrl=[file:///home/marco/.var/app/io.github.mmarco94.tambourine/cache/tmp/album-cover-17548945203412798889.png]}], CanGoNext=[true], CanGoPrevious=[true], CanPlay=[true], CanPause=[true], CanSeek=[true], CanControl=[true]}, []
2023-06-19 23:49:44.085 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Creating message with serial 14
2023-06-19 23:49:44.085 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: yyyy data: 108, 4, 0, 1
2023-06-19 23:49:44.086 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: ua(yv) data: 15, [[1, [o, /org/mpris/MediaPlayer2]], [2, [s, org.freedesktop.DBus.Properties]], [3, [s, PropertiesChanged]], [8, [g, sa{sv}as]]]
2023-06-19 23:49:44.086 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | <= PropertiesChanged[propertiesChanged={PlaybackStatus=[Paused], LoopStatus=[Playlist], Metadata=[{mpris:trackid=[/io/github/MMarco94/music-player/-997585971], mpris:length=[234031020], xesam:artist=[[ABBA]], xesam:albumArtist=[[ABBA]], xesam:album=[Arrival], xesam:title=[My Love, My Life], xesam:discNumber=[3], mpris:artUrl=[file:///home/marco/.var/app/io.github.mmarco94.tambourine/cache/tmp/album-cover-17548945203412798889.png]}], CanGoNext=[true], CanGoPrevious=[true], CanPlay=[true], CanPause=[true], CanSeek=[true], CanControl=[true]}, propertiesRemoved=[], interfaceName='org.mpris.MediaPlayer2.Player']
2023-06-19 23:49:44.089 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: sa{sv}as data: org.mpris.MediaPlayer2.Player, {PlaybackStatus=[Playing]}, []
2023-06-19 23:49:44.089 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | <= PropertiesChanged[propertiesChanged={PlaybackStatus=[Playing]}, propertiesRemoved=[], interfaceName='org.mpris.MediaPlayer2.Player']
2023-06-19 23:49:44.090 | DEBUG | org.freedesktop.dbus.spi.message.InputStreamMessageReader | => MethodCall(0,1990) { Invalid=>null, Path=>/org/mpris/MediaPlayer2, Interface=>org.freedesktop.DBus.Properties, Member=>Get, Error Name=>null, Reply Serial=>null, Destination=>:1.472, Sender=>:1.39, Signature=>ss, Unix FD=>null } { org.mpris.MediaPlayer2.Player, Position }
2023-06-19 23:49:44.090 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Handling incoming method call: MethodCall(0,1990) { Invalid=>null, Path=>/org/mpris/MediaPlayer2, Interface=>org.freedesktop.DBus.Properties, Member=>Get, Error Name=>null, Reply Serial=>null, Destination=>:1.472, Sender=>:1.39, Signature=>ss, Unix FD=>null } { org.mpris.MediaPlayer2.Player, Position }
2023-06-19 23:49:44.090 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Running method public abstract java.lang.Object org.freedesktop.dbus.interfaces.Properties.Get(java.lang.String,java.lang.String) for remote call
2023-06-19 23:49:44.090 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Creating message with serial 15
2023-06-19 23:49:44.090 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Appending sig: yyyy data: 108, 2, 0, 1
2023-06-19 23:49:44.091 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Appending sig: ua(yv) data: 15, [[5, [u, 1990]], [6, [s, :1.39]], [8, [g, v]]]
2023-06-19 23:49:44.091 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Appending sig: v data: [127959]
2023-06-19 23:49:44.091 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | <= MethodReturn(0,15) { Invalid=>null, Path=>null, Interface=>null, Member=>null, Error Name=>null, Reply Serial=>1990, Destination=>:1.39, Sender=>null, Signature=>v, Unix FD=>null } { [127959] }

** (process:68810): WARNING **: 23:49:44.091: Invalid client serial
2023-06-19 23:49:44.092 | ERROR | org.freedesktop.dbus.connections.IncomingMessageThread | FatalException in connection thread
org.freedesktop.dbus.exceptions.FatalDBusException: java.io.EOFException: (1) Underlying transport returned -1
        at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1180)
        at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:42)
Caused by: java.io.EOFException: (1) Underlying transport returned -1
        at org.freedesktop.dbus.spi.message.InputStreamMessageReader.readMessage(InputStreamMessageReader.java:47)
        at org.freedesktop.dbus.connections.transports.AbstractTransport.readMessage(AbstractTransport.java:89)
        at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1169)
        ... 1 common frames omitted
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Disconnecting Abstract Connection
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: SignalExecutor
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: MethodReturnExecutor
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: MethodCallExecutor
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: ErrorExecutor
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Interrupted while waiting for termination of executor
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Notifying 0 method call(s) to stop waiting for replies
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Shutting down SenderService
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.transport.jre.NativeUnixSocketTransport | Disconnecting Transport
2023-06-19 23:49:44.093 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | Closing Message Writer

@hypfvieh
Copy link
Owner

This issue reminds me of #177. In that bug the problem was wrong/missing whitelisting for some DBus calls the application wants to do.
Maybe you can read the old ticket and check if this is not the same problem.

@MMarco94
Copy link
Author

Thanks for the reply!

I'll give it another shot later today, however I'm pretty sure it's not a permission issue:

  • If I purposely request a DBus name I'm not allowed to use, the error is completely different
  • Other apps with the same use case have the same permissions as mine

@MMarco94
Copy link
Author

Let me add another piece of information. When I run the app with flatpak run --log-session-bus ..., I get these additional messages:

C1: -> org.freedesktop.DBus call org.freedesktop.DBus.Hello at /org/freedesktop/DBus
C2: -> org.freedesktop.DBus fake wildcarded AddMatch for org.freedesktop.portal
C3: -> org.freedesktop.DBus fake wildcarded AddMatch for org.mpris.MediaPlayer2.io.github.mmarco94.tambourine
C4: -> org.freedesktop.DBus fake wildcarded AddMatch for io.github.mmarco94.tambourine
C5: -> org.freedesktop.DBus fake ListNames
B1: <- org.freedesktop.DBus return from C1
B2: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameAcquired at /org/freedesktop/DBus
B3: <- org.freedesktop.DBus return from C2
*SKIPPED*
B4: <- org.freedesktop.DBus return from C3
*SKIPPED*
B5: <- org.freedesktop.DBus return from C4
*SKIPPED*
B6: <- org.freedesktop.DBus return from C5
C6: -> org.freedesktop.DBus fake GetNameOwner for org.freedesktop.DBus
C7: -> org.freedesktop.DBus fake GetNameOwner for org.freedesktop.portal.Desktop
C8: -> org.freedesktop.DBus fake GetNameOwner for org.freedesktop.portal.Documents
*SKIPPED*
B7: <- org.freedesktop.DBus return from C6
*SKIPPED*
B8: <- org.freedesktop.DBus return from C7
*SKIPPED*
B9: <- org.freedesktop.DBus return from C8
*SKIPPED*
C10: -> org.freedesktop.DBus call org.freedesktop.DBus.RequestName at /org/freedesktop/DBus
B12: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B10: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameAcquired at /org/freedesktop/DBus
B11: <- org.freedesktop.DBus return from C10
B347: <- :1.38 call org.freedesktop.DBus.Properties.GetAll at /org/mpris/MediaPlayer2
B94: <- :1.55 call org.freedesktop.DBus.Properties.GetAll at /org/mpris/MediaPlayer2
B348: <- :1.38 call org.freedesktop.DBus.Properties.GetAll at /org/mpris/MediaPlayer2
B1729: <- :1.21 call org.freedesktop.DBus.Properties.GetAll at /org/mpris/MediaPlayer2
B1730: <- :1.21 call org.freedesktop.DBus.Properties.GetAll at /org/mpris/MediaPlayer2
C12: -> :1.38 return from B347
C13: -> :1.55 return from B94
C14: -> :1.38 return from B348
C15: -> :1.21 return from B1729
C16: -> :1.21 return from B1730


C18: -> all signal org.freedesktop.DBus.Properties.PropertiesChanged at /org/mpris/MediaPlayer2
C19: -> all signal org.freedesktop.DBus.Properties.PropertiesChanged at /org/mpris/MediaPlayer2
B349: <- :1.38 call org.freedesktop.DBus.Properties.Get at /org/mpris/MediaPlayer2

** (process:6985): WARNING **: 19:22:15.512: Invalid client serial

And after this the DBus socket closes.

I can't see anything obviously wrong TBH, but maybe I'm missing something

@MMarco94
Copy link
Author

And just for completeness, let me send the logs from both the Flatpak runtime and your library. Before this point, the DBus was open and working. Then I performed an action in the app, and this was logged:

2023-06-20 19:39:03.035 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Creating message with serial 12
2023-06-20 19:39:03.035 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: yyyy data: 108, 4, 0, 1
2023-06-20 19:39:03.036 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: ua(yv) data: 13, [[1, [o, /org/mpris/MediaPlayer2]], [2, [s, org.freedesktop.DBus.Properties]], [3, [s, PropertiesChanged]], [8, [g, sa{sv}as]]]
2023-06-20 19:39:03.036 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: sa{sv}as data: org.mpris.MediaPlayer2.Player, {PlaybackStatus=[Paused], LoopStatus=[Playlist], Metadata=[{mpris:trackid=[/io/github/MMarco94/music-player/128002443], mpris:length=[262948571], xesam:artist=[[ABBA]], xesam:albumArtist=[[ABBA]], xesam:album=[Voulez-Vous], xesam:title=[Angel Eyes], xesam:discNumber=[4], mpris:artUrl=[file:///home/marco/.var/app/io.github.mmarco94.tambourine/cache/tmp/album-cover-18143074990268500424.png]}], CanGoNext=[true], CanGoPrevious=[true], CanPlay=[true], CanPause=[true], CanSeek=[true], CanControl=[true]}, []
2023-06-20 19:39:03.037 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Creating message with serial 13
2023-06-20 19:39:03.037 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: yyyy data: 108, 4, 0, 1
2023-06-20 19:39:03.037 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: ua(yv) data: 14, [[1, [o, /org/mpris/MediaPlayer2]], [2, [s, org.freedesktop.DBus.Properties]], [3, [s, PropertiesChanged]], [8, [g, sa{sv}as]]]
2023-06-20 19:39:03.037 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | <= PropertiesChanged[propertiesChanged={PlaybackStatus=[Paused], LoopStatus=[Playlist], Metadata=[{mpris:trackid=[/io/github/MMarco94/music-player/128002443], mpris:length=[262948571], xesam:artist=[[ABBA]], xesam:albumArtist=[[ABBA]], xesam:album=[Voulez-Vous], xesam:title=[Angel Eyes], xesam:discNumber=[4], mpris:artUrl=[file:///home/marco/.var/app/io.github.mmarco94.tambourine/cache/tmp/album-cover-18143074990268500424.png]}], CanGoNext=[true], CanGoPrevious=[true], CanPlay=[true], CanPause=[true], CanSeek=[true], CanControl=[true]}, propertiesRemoved=[], interfaceName='org.mpris.MediaPlayer2.Player']
C20: -> all signal org.freedesktop.DBus.Properties.PropertiesChanged at /org/mpris/MediaPlayer2
2023-06-20 19:39:03.040 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: sa{sv}as data: org.mpris.MediaPlayer2.Player, {PlaybackStatus=[Playing]}, []
2023-06-20 19:39:03.040 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | <= PropertiesChanged[propertiesChanged={PlaybackStatus=[Playing]}, propertiesRemoved=[], interfaceName='org.mpris.MediaPlayer2.Player']
C21: -> all signal org.freedesktop.DBus.Properties.PropertiesChanged at /org/mpris/MediaPlayer2
B444: <- :1.38 call org.freedesktop.DBus.Properties.Get at /org/mpris/MediaPlayer2
2023-06-20 19:39:03.041 | DEBUG | org.freedesktop.dbus.spi.message.InputStreamMessageReader | => MethodCall(0,444) { Invalid=>null, Path=>/org/mpris/MediaPlayer2, Interface=>org.freedesktop.DBus.Properties, Member=>Get, Error Name=>null, Reply Serial=>null, Destination=>:1.148, Sender=>:1.38, Signature=>ss, Unix FD=>null } { org.mpris.MediaPlayer2.Player, Position }
2023-06-20 19:39:03.042 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Handling incoming method call: MethodCall(0,444) { Invalid=>null, Path=>/org/mpris/MediaPlayer2, Interface=>org.freedesktop.DBus.Properties, Member=>Get, Error Name=>null, Reply Serial=>null, Destination=>:1.148, Sender=>:1.38, Signature=>ss, Unix FD=>null } { org.mpris.MediaPlayer2.Player, Position }
2023-06-20 19:39:03.042 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Running method public abstract java.lang.Object org.freedesktop.dbus.interfaces.Properties.Get(java.lang.String,java.lang.String) for remote call
2023-06-20 19:39:03.042 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Creating message with serial 14
2023-06-20 19:39:03.042 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Appending sig: yyyy data: 108, 2, 0, 1
2023-06-20 19:39:03.042 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Appending sig: ua(yv) data: 14, [[5, [u, 444]], [6, [s, :1.38]], [8, [g, v]]]
2023-06-20 19:39:03.042 | DEBUG | org.freedesktop.dbus.messages.MethodReturn | Appending sig: v data: [127959]
2023-06-20 19:39:03.043 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | <= MethodReturn(0,14) { Invalid=>null, Path=>null, Interface=>null, Member=>null, Error Name=>null, Reply Serial=>444, Destination=>:1.38, Sender=>null, Signature=>v, Unix FD=>null } { [127959] }

** (process:9689): WARNING **: 19:39:03.043: Invalid client serial
2023-06-20 19:39:03.043 | ERROR | org.freedesktop.dbus.connections.IncomingMessageThread | FatalException in connection thread
org.freedesktop.dbus.exceptions.FatalDBusException: java.io.EOFException: (1) Underlying transport returned -1
        at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1180)
        at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:42)
Caused by: java.io.EOFException: (1) Underlying transport returned -1
        at org.freedesktop.dbus.spi.message.InputStreamMessageReader.readMessage(InputStreamMessageReader.java:47)
        at org.freedesktop.dbus.connections.transports.AbstractTransport.readMessage(AbstractTransport.java:89)
        at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1169)
        ... 1 common frames omitted
2023-06-20 19:39:03.044 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Disconnecting Abstract Connection
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: SignalExecutor
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: MethodReturnExecutor
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: MethodCallExecutor
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Shutting down executor: ErrorExecutor
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.ReceivingService | Interrupted while waiting for termination of executor
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Notifying 0 method call(s) to stop waiting for replies
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.connections.impl.DBusConnection | Shutting down SenderService
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.transport.jre.NativeUnixSocketTransport | Disconnecting Transport
2023-06-20 19:39:03.045 | DEBUG | org.freedesktop.dbus.spi.message.OutputStreamMessageWriter | Closing Message Writer
2023-06-20 19:39:03.411 | DEBUG | io.github.mmarco94.tambourine.audio.PlayerController | Reading Angel Eyes took 424ms
2023-06-20 19:39:03.413 | DEBUG | io.github.mmarco94.tambourine.audio.PlayerController | Computing waveform for Angel Eyes took 426ms
2023-06-20 19:39:04.344 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Creating message with serial 15
2023-06-20 19:39:04.344 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: yyyy data: 108, 4, 0, 1
2023-06-20 19:39:04.344 | DEBUG | org.freedesktop.dbus.interfaces.Properties$PropertiesChanged | Appending sig: ua(yv) data: 16, [[1, [o, /org/mpris/MediaPlayer2]], [2, [s, org.freedesktop.DBus.Properties]], [3, [s, PropertiesChanged]], [8, [g, sa{sv}as]]]
2023-06-20 19:39:04.345 | ERROR | io.github.mmarco94.tambourine.mpris.MPRISPlayerController | Cannot send message to the DBus: Cannot send message: Not connected

@MMarco94
Copy link
Author

MMarco94 commented Jun 20, 2023

Sorry for the amount of messages, but I have another question: why here and here the signal is incremented?

What happens is that a message sent to a DBus after a DBusSignal will get the same serial as the previous message (since GLOBAL_SERIAL is not incremented). That might be the reason why xdg-dbus-proxy says Invalid client serial

Edit: I was able to almost confirm this is in fact the bug!
By creating a new message (just to increment the global counter), everything works!

            PropertiesChanged(objectPath, interfaceName, diffs, emptyList()).also {
                // Ugly workaround until https://github.com/hypfvieh/dbus-java/issues/220 is fixed
                DBusSignal("", "", "", "", "")
            }

MMarco94 pushed a commit to MMarco94/tambourine-music-player that referenced this issue Jun 20, 2023
This allows the app to not require full session-dbus access.

Will remove the workaround when hypfvieh/dbus-java#220 is fixed
@hypfvieh
Copy link
Owner

hypfvieh commented Jun 21, 2023

This is not really a bug, because the DBus specification does not say anything (or forces you) to use consecutive serials in messages (including signals). The only important thing is that the serial is unique and that if the serial is used for a method call, it can be mapped to the return value of that call.

The reason why a serial number is omitted here is that the signals received on the bus are created using reflection. This reflection call will use the DBusSignal constructor which will always increment the global serial counter. The created signal object is only passed to the signal handler code. Therefore the serial will never be seen on the bus and will never be re-used.
Decrementing the serial later after construction is too late (serial has already been written to the internal message byte array).
This can also cause strange issues when it comes to concurrency.

Regarding xdg-dbus-proxy: it wants to enforce consecutive serials even though DBus specification does not.
There is a open bug describing this: flatpak/xdg-dbus-proxy#46

I'll have a look if I can change the handling of the global serial but I'm convinced dbus-java is not doing anything wrong.

@MMarco94
Copy link
Author

I might be mistaken, but I don't think this is a problem of monotonicity.

The problem here is that a message sent after a DBus signal will reuse the same identifier.

hypfvieh added a commit that referenced this issue Jun 21, 2023
…use it will conflict with the next created message
@hypfvieh
Copy link
Owner

I removed the part with the serial in DBusSignal. This was some weird code which was in the library since day one.

@MMarco94
Copy link
Author

That's amazing, thank you so much!

@MMarco94
Copy link
Author

QQ: I see the maven version has been bumped to 4.3.1-SNAPSHOT.

  • Is there an ETA for the release of the fix?
  • Is there a way for me to use the snapshot version?

Thanks again for your work!

@hypfvieh
Copy link
Owner

No there is no ETA. It's done when it's done.

Using snapshots must be configured in maven or your project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants