dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.16k stars 794 forks source link

IPv4 localhost (127.0.0.1) is no longer default host with Node 18 #1783

Open rynkowsg opened 2 months ago

rynkowsg commented 2 months ago

Bug Report

With upgrade from Node 16 to 18, I noticed the IPv4 localhost (127.0.0.1) is no longer used. By default is used IPv6 localhost (::1). From curl with -vvv option:

*   Trying 127.0.0.1:3000...                                                                                                                                                                                                                 
* connect to 127.0.0.1 port 3000 failed: Connection refused                                                                                                                                                                                  
*   Trying [::1]:3000...                                                                                                                                                                                                                     
* Connected to localhost (::1) port 3000 (#0)       

While it is not a problem for curl, it is a problem when one tries to call localhost with other clients, e.g. hosted on JVM. Trying to reach localhost:3000 from Java (tested on Java 11 & 17), results with:

Execution error (ClosedChannelException) at sun.nio.ch.SocketChannelImpl/ensureOpen (SocketChannelImpl.java:195).

Current Behavior

IPv4 localhost is not available. It is possible to use it but host: 127.0.0.1 needs to be specified in config, otherwise by default service is available under ::1.

Sample Code

service: my-service

plugins:
  - serverless-offline

provider:
  runtime: nodejs18.x
  stage: dev

functions:
  hello:
    events:
      - http:
          method: get
          path: hello
    handler: handler.hello

custom:
  serverless-offline:
    port: 3000
    # host is not specified

Expected behavior/code

Either make IPv4 localhost (127.0.0.1) reachable by default, or clear messaging in logs is needed that service is running exclusively on IPv6 localhost (::1).

Environment

DorianMazur commented 1 month ago

@rynkowsg I can't reproduce the issue. Can you share a sample repo? The link to the sample app you gave doesn't seem to be a good example of the issue you are describing.