fukamachi / woo

A fast non-blocking HTTP server on top of libev
http://ultra.wikia.com/wiki/Woo_(kaiju)
MIT License
1.28k stars 98 forks source link

Support IPv6 #53

Closed svetlyak40wt closed 8 years ago

svetlyak40wt commented 8 years ago

Is it hard to support binding to IPv6 in Woo?

I found woo is the only handler for Clack which accepts :address argument, but when I pass "::0" it is failing. And looking at the code seems it only support IPv4 for now.

I have a bunch os IPv6 only backends and want to run ningle based microservice on them. Having support for IPv6 in Woo whould be wonderful!

P.S. — found a great tutorial Porting applications to IPv6 HowTo . May be will be able to fix woo myself. Anyway, any guidance from you will be highly appreciated! Thank you for great libraries!

svetlyak40wt commented 8 years ago

Found a workaround – start an woo server on a unix socket and proxy to it from local Nginx. But it doesn't work. Unix socket is created, but I make request to nginx, woo server writes to stdout:

<ERROR> [08:18:32] woo.ev.tcp - Can't accept connection (Code: 14)

and nginx returns 502 Bad Gateway, outputting to logs:

2016/08/06 08:22:22 [error] 60#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.17.0.1, server: , request: "GET /info HTTP/1.1", upstream: "http://unix:/app.sock:/info", host: "localhost:8000"
172.17.0.1 - - [06/Aug/2016:08:22:22 +0000] "GET /info HTTP/1.1" 502 181 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17"

Seems, error 14, mentioned by woo, is:

#define EFAULT      14  /* Bad address */

Do you have any ideas what is wrong and how to fix it?

Here is nginx config I used:

daemon off;
worker_processes 1;
pid /nginx.pid;
error_log /dev/stdout info;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
 access_log /dev/stdout;

 server {
  listen 80;

  location / {
    proxy_pass http://unix:/app.sock:/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
 }
}
fukamachi commented 8 years ago

The EFAULT error is because the sockaddr_in is short for IPv6 addresses. Replacing it by sockaddr_in6 or sockaddr_storage might work.

svetlyak40wt commented 8 years ago

By the way, workaround with unix-socket worked after patch from @knobo was applied. I started supervisord and lisp + nginx under it. Nginx listens on [::]80 and proxies to unix-socket.

But I feel something wrong to have such configuration inside a docker container.

fukamachi commented 8 years ago

Implemented at #55. I'll merge it after some benchmarks and performance improvements.

@svetlyak40wt Could you give a try the ipv6 branch?

svetlyak40wt commented 8 years ago

Sure.