Giter Club home page Giter Club logo

Comments (4)

shenfeng avatar shenfeng commented on May 12, 2024

http-kit reuses the AsyncChannel object. AsyncChannel is per connection. A connection is a TCP connection. Since browser or JMeter will try to use the TCP connection, AsyncChannel get reused. When reused, AsyncChannel get reseted https://github.com/http-kit/http-kit/blob/master/src/java/org/httpkit/server/AsyncChannel.java#L73

Since the reset is lazyset, maybe this is where the problem is.

http-kit only allow set the closeHandler once, maybe this is a bad design. How do you think about it?

As regarding the multiple threads, how about this:
Do not use PipedInputStream or PipedOutputStream. Instead of write to the PipedOutputStream, just write to channel. http-kit is multi-threaded, blocking a few thread will be fine. Set :thread option to a larger value will be fine http://http-kit.org/server.html#options

from http-kit.

cndreisbach avatar cndreisbach commented on May 12, 2024

This helped so much! Thank you, @shenfeng.

As for only allowing the closeHandler once, I think it's ok, although it is confusing since the reset is lazyset and you can encounter a situation where you think the closeHandler is not set but it actually is.

When you say "just write to channel," what do you mean, exactly? I am generating a stream of JSON or XML text and need an OutputStream for it to go into. The channel's not an OutputStream, so I'm not certain the best way to go about that.

from http-kit.

shenfeng avatar shenfeng commented on May 12, 2024

I will try to reproduce and fix the issue with closeHandler, It maybe a multi thread bug of http-kit.

The channel's not an OutputStream

You can create a method, like:
ch->outputstream

(defn ch->outputstream [ch]
  (proxy [java.io.OutputStream] []
    (close []
       )
    (write
      ([bs] ;; bytes of byte
             ;; write to channel
         )
      ([^bytes bs off  len]
         ))))

from http-kit.

shenfeng avatar shenfeng commented on May 12, 2024

Hi, I look at the code carefully, the reset is threadsafe, should ok.
Can you help by show test case to reproduce the problem?

from http-kit.

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.