serverless-offline icon indicating copy to clipboard operation
serverless-offline copied to clipboard

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

Open rynkowsg opened this issue 1 year ago • 1 comments

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

  • file: serverless.yml
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

  • serverless version: 3.38.0
  • serverless-offline version: 13.5.0
  • node.js version: v18.20.2
  • OS: Fedora 38

rynkowsg avatar May 01 '24 14:05 rynkowsg

@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.

DorianMazur avatar May 19 '24 13:05 DorianMazur