Skip to content

Build attempts connection to dependent services #933

@kubejm

Description

@kubejm

Describe the bug
I have a SvelteKit application which connects to a dependent service via a socket using createConnection from the net module. During the build process to create production assets via the npm run build script, it appears to try run my modules, which results in attempting to create the socket to the dependent service.

If the service is up, then the socket connection is established and npm run build hangs on the open socket, so it does not finish. However, if the service is down, then the socket connection fails, which results in error outputs of the failed connection during the build, and the build finishes.

I intentionally desired a socket connection on startup of the application, so I did not need to make a new connection upon each request.

Logs
Listed below are outputs during the build process for when the dependent service is up and also for when it is down. To set some context, the name of the relative service is spidey-db and it runs on port 6425.

Output when dependent service is up. "connected to spidey db" is a debug log statement for reference

❯ npm run build

> spidey-db-demo@0.0.1 build
> svelte-kit build

vite v2.1.5 building for production...
✓ 586 modules transformed.
.svelte/output/client/_app/manifest.json                            0.85kb
.svelte/output/client/_app/chunks/index-79739b24.js                 0.48kb / brotli: 0.28kb
.svelte/output/client/_app/assets/start-a8cd1609.css                0.16kb / brotli: 0.10kb
.svelte/output/client/_app/assets/pages/index.svelte-0b0729a2.css   1.95kb / brotli: 0.70kb
.svelte/output/client/_app/chunks/vendor-9102d6d9.js                5.17kb / brotli: 2.01kb
.svelte/output/client/_app/start-b972c043.js                        15.73kb / brotli: 5.36kb
.svelte/output/client/_app/pages/index.svelte-f2643f1e.js           62.10kb / brotli: 17.92kb
vite v2.1.5 building SSR bundle for production...
✓ 38 modules transformed.
.svelte/output/server/app.js   103.22kb

Run npm start to try your app locally.

> Using @sveltejs/adapter-node
  ✔ done
connected to spidey db

Output when dependent service is down.

❯ npm run build

> spidey-db-demo@0.0.1 build
> svelte-kit build

vite v2.1.5 building for production...
✓ 586 modules transformed.
.svelte/output/client/_app/manifest.json                            0.85kb
.svelte/output/client/_app/chunks/index-79739b24.js                 0.48kb / brotli: 0.28kb
.svelte/output/client/_app/assets/start-a8cd1609.css                0.16kb / brotli: 0.10kb
.svelte/output/client/_app/chunks/vendor-9102d6d9.js                5.17kb / brotli: 2.01kb
.svelte/output/client/_app/assets/pages/index.svelte-0b0729a2.css   1.95kb / brotli: 0.70kb
.svelte/output/client/_app/start-b972c043.js                        15.73kb / brotli: 5.36kb
.svelte/output/client/_app/pages/index.svelte-f2643f1e.js           62.10kb / brotli: 17.92kb
vite v2.1.5 building SSR bundle for production...
✓ 38 modules transformed.
.svelte/output/server/app.js   103.22kb

Run npm start to try your app locally.

> Using @sveltejs/adapter-node
  ✔ done
node:events:353
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:6425
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1138:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6425
}

To Reproduce
This could be reproduced by creating a socket connection within a module, then running build.

This can be replicated with the following folder in the following repository:
https://github.com/kubejm/spidey-db-demo/tree/master/packages/webapp

The socket connection within the repository above can be found here:
https://github.com/kubejm/spidey-db-demo/blob/master/packages/webapp/src/lib/spidey-db/client.ts#L87-L97

The connection is established here:
https://github.com/kubejm/spidey-db-demo/blob/master/packages/webapp/src/lib/spidey-db/index.ts#L6-L9

Expected behavior
Not executing the module within my application code, which attempts to establish a socket connection.

I'm new to Svelte/SvelteKit, so I'm not aware of the build process to produce the production assets. However, ideally it would not need to instantiate/run my assets with the @sveltejs/adapter-node to produce them.

Information about your SvelteKit Installation:

Diagnostics
❯ npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
Need to install the following packages:
  envinfo
Ok to proceed? (y) y

  System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
    Memory: 9.36 GB / 15.60 GB
    Container: Yes
    Shell: 3.2.1 - /usr/bin/fish
  Binaries:
    Node: 15.4.0 - ~/.local/share/nvm/v15.4.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 7.7.5 - ~/.local/share/nvm/v15.4.0/bin/npm
  Browsers:
    Chromium: 89.0.4389.114
    Firefox: 87.0
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.71
    svelte: ^3.29.0 => 3.37.0
    vite: ^2.1.0 => 2.1.5

Adapter: @sveltejs/adapter-node

Severity
This is a side project to learn Svelte and SvelteKit, so no urgency on this for me. I am hoping to run this application in Docker, so I'm trying to work towards a production-like state by building the assets and running it within a container.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions