Giter VIP home page Giter VIP logo

Comments (3)

noteflakes avatar noteflakes commented on May 18, 2024

I couldn't reproduce your issue, but then again I'm on Linux. How are you making requests to your server script? Using curl or a browser? If you're using a browser you'll see two requests because the browser makes a second request to /favicon.ico.

Please try the following code:

require 'bundler/setup'
require 'tipi'

puts 'Serving on http://localhost:4411/'
spin do
  Tipi.serve('0.0.0.0', 4411, { reuse_addr: true }) do |req|
    req.uri
    req.respond("Hello world!\n")
  rescue Exception => e
    p e
  end
  p 'done...'
end.await

This will print the requested uri for each incoming request.

As for the server port leaking after the process terminates, I have also noticed that. Here's an explanation for what's apparently happening (from https://hea-www.harvard.edu/~fine/Tech/addrinuse.html):

In order for a network connection to close, both ends have to send FIN (final) packets, which indicate they will not send any additional data, and both ends must ACK (acknowledge) each other's FIN packets. The FIN packets are initiated by the application performing a close(), a shutdown(), or an exit(). The ACKs are handled by the kernel after the close() has completed. Because of this, it is possible for the process to complete before the kernel has released the associated network resource, and this port cannot be bound to another process until the kernel has decided that it is done.

The solution is to use the reuse_addr option when calling Tipi.serve, as shown in the above example.

from tipi.

noteflakes avatar noteflakes commented on May 18, 2024

Please note that the request / response API is still evolving, and has actually been extracted into a separate gem: https://rubygems.org/gems/qeweney. Documentation is lacking for the moment.

from tipi.

skovsboll avatar skovsboll commented on May 18, 2024

You're right, it was the favicon! Why did I not think of that 😬
Thank you for explaining the background of requiring reuse_addr. Awesome gem, you've made! 😄
I'll check out qeweney -- noticed you're building a Roda style routing. I love the Roda/Sequel stack.

from tipi.

Related Issues (19)

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.