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

metadata not properly encoded when sending requestStream with BearerAuthMetadata(jwt) #234

Open
kumaraish opened this issue May 1, 2023 · 3 comments
Assignees
Labels

Comments

@kumaraish
Copy link

metadata in REQUEST_STREAM is not properly encoded when compositeMetadata is used and it includes both RoutingMetadata and BearerAuthMetadata

Expected Behavior

The following requestStream should be accepted by the Spring Boot Rsocket Server

scope.launch {
  rsocket
  .requestStream(
    buildPayload {
      data(ByteReadPacket(clientId.toByteArray())) // clientid is 1523ad4b-5035-4791-a788-3268a98e296a
      compositeMetadata {
        add(RoutingMetadata("api.v1.authenticate"))
        add(BearerAuthMetadata(jwt))  // jwt is a 1192 characters long token
      }
    }
  )
  .catch { console.log("Exception ${it.message}") }   // 'metadata is malformed'
  .onEach { handler(it) }
  .launchIn(this)
}

The exact same code works when sending a requestResponse() frame

In the Setup Frame, payload MimeType is MessageRSocketCompositeMetadata. Setup frame doesn't sends any metadata

PayloadMimeType(
    data = WellKnownMimeType.ApplicationJson,
    metadata = WellKnownMimeType.MessageRSocketCompositeMetadata
  )

Actual Behavior

The Server returns ERROR frame with 'metadata is malformed'

  • SETUP FRAME
    SETUP FRAME

  • REQUEST_RESPONSE FRAME
    REQUEST_RESPONSE FRAME

  • REQUEST_STREAM FRAME (Reported 'metadata is malformed' by the server)
    REQUEST_STREAM FRAME

Steps to Reproduce

Possible Solution

Your Environment

  • RSocket version(s) used: io.rsocket.kotlin:rsocket-core:0.15.4 and io.rsocket.kotlin:rsocket-ktor-client:0.15.4
  • Platform (eg. JVM version (javar -version) or Node version (node --version)): JAVA 19
  • OS and version (eg uname -a): Ubuntu 20.04.6 LTS
@whyoleg
Copy link
Member

whyoleg commented May 2, 2023

Hey!

Thx for the report, though it's hard to understand what is the issue on current moment.
Can you please add frame logging on client or server side (via rsocket-java/rsocket-kotlin functionality) and post frame logs here (or via link to gist)?
As for rsocket-kotlin (on client side) you will need to add loggerFactory = PrintLogger.withLevel(LoggingLevel.DEBUG) to connector configuration.
f.e. if you are using ktor-client integration:

install(RSocketSupport) {
  connector {
    loggerFactory = PrintLogger.withLevel(LoggingLevel.DEBUG)
  }
}

Also, do you have some custom client / server configuration regarding fragmentation, like maxFragmentSize in rsocket-kotlin?

@kumaraish
Copy link
Author

You are so correct !! I had maxFragmentSize = 1024 set in rsocket-kotlin
If I remove that, that error is gone...

I had copied it right from the //create ktor client example on https://github.com/rsocket/rsocket-kotlin

Is using maxFragmentSize = 1024 an issue?

@whyoleg
Copy link
Member

whyoleg commented May 2, 2023

Good to hear that it solves issue on your side!
Overall using maxFragmentSize should not cause any issues, but overall - stick with defaults unless needed :)
Example in README just shows what is possible to configure, may be we need to cleanup it a bit to make it more robust.

Though, you report confirms that there is a bug somewhere in fragmentation logic inside rsocket-kotlin regarding handling of request stream/channel frames (likely because of additional initialRequest field, that could be handled differently).
I believe rsocket-java implementation is correct, so I think that I will setup some cross-implementation testing in future (at least for fragmentation use case).

@whyoleg whyoleg self-assigned this May 2, 2023
@whyoleg whyoleg added the bug label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants