Giter Club home page Giter Club logo

Comments (6)

msdousti avatar msdousti commented on June 12, 2024

TLDR: The issue is more general than using the ContentNegotiation plugin. It has to do with requests that don't have a body.

While running the server with a GET endpoint, and sending a GET request, I see this in the logs:

java.lang.IllegalStateException: No instance for key AttributeKey: Logbook.ResponseProcessingStage

The issue is in a map lookup here (where responseProcessingStageKey = AttributeKey("Logbook.ResponseProcessingStage")):

val responseProcessingStage = call.attributes[responseProcessingStageKey]

The map was supposed to be filled by the proper value here:

call.attributes.put(responseProcessingStageKey, responseProcessingStage)

The above line is executed when intercepting the Receive Pipeline during the ApplicationReceivePipeline.Before phase:

pipeline.receivePipeline.intercept(ApplicationReceivePipeline.Before) {

As per Ktor docs for ApplicationReceivePipeline:

A pipeline for processing incoming content. When executed, this pipeline starts with an instance of ByteReadChannel.

Using a debugger, I noted that this phase is only executed when the request has some content (body). The unit tests also set up the server with POST endpoints:

private val server = embeddedServer(CIO, port = port) {
install(LogbookServer) {
logbook = testLogbook
}
routing {
post("/echo") {
call.response.headers.append("Content-Type", "Text/Plain", false)
call.respondText(call.receiveText())
}
post("/discard") {
call.receiveText()
call.respond(HttpStatusCode.OK)
}
}
}


@grassehh Based on the above explanation, do you know how to fix the issue?

from logbook.

msdousti avatar msdousti commented on June 12, 2024

PS: The receive pipeline can be manually triggered by something like this (here, I added call.receiveText() to your code):

data class SomeData(val someProp: String)
route("/test") {
     get {
       call.receiveText()
       call.respond(SomeData("someValue")) 
     }
}

from logbook.

adarshjhaa100 avatar adarshjhaa100 commented on June 12, 2024

Would like to diagnose and fix this issue if its up for grabs

from logbook.

msdousti avatar msdousti commented on June 12, 2024

Would like to diagnose and fix this issue if its up for grabs

@adarshjhaa100 Thanks a lot, true open source spirit!
Any help is appreciated. I did a very preliminary diagnosis in the two comments above yours. For the rest, I'll count on your expertise buddy 💯

from logbook.

grassehh avatar grassehh commented on June 12, 2024

PS: The receive pipeline can be manually triggered by something like this (here, I added call.receiveText() to your code):

data class SomeData(val someProp: String)
route("/test") {
     get {
       call.receiveText()
       call.respond(SomeData("someValue")) 
     }
}

Thanks for the analysis. Indeed we also did notice this issue for GET routes on our project. The workaround as you mentionned is to manually trigger the pipeline by calling one of the call.receive() methods.
However I did not mention that in this issue as we thought this is not related.
Unfortunatly, I don't have enough Ktor expertise (and especially about its pipeline mecanism) in order to find the fix yet.

from logbook.

grassehh avatar grassehh commented on June 12, 2024

Hello, @ChristianLohmann @msdousti, is there any update about the No instance for key AttributeKey: Logbook.ResponseProcessingStage issue ?

from logbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.