question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build attempts connection to dependent services

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
benmccanncommented, Apr 18, 2021

@n4bb12 there’s a separate issue for that: https://github.com/sveltejs/kit/issues/978

0reactions
kubejmcommented, Sep 11, 2021

I apologize for the delay on vetting this.

I have pulled down the latest versions of @sveltejs/kit (1.0.0-next.165) and @sveltejs/adapter-node (1.0.0-next.46), then converted my svelte.config.cjs to svelte.config.js. I am no longer experiencing the issue I initially raised. It builds successfully and runs as expected.

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service Dependency - an overview | ScienceDirect Topics
Many ISA fans attempted to divine the service dependencies, but no hard and fast guidance was ever developed. To make life even more...
Read more >
Dependency injection guidelines - .NET | Microsoft Learn
When designing services for dependency injection: ... Attempt to refactor the class by moving some of its responsibilities into new classes.
Read more >
Kubernetes Demystified: Solving Service Dependencies
In the third article of this series, we will explore how we can handle dependencies between services when using Kubernetes.
Read more >
Control startup and shutdown order in Compose
Compose always starts and stops containers in dependency order, where dependencies are determined by depends_on , links , volumes_from , and network_mode: " ......
Read more >
How to Fix The Dependency Service or Group Failed to Start
What causes dependency service errors? ... and all networks regardless of whether they try to connect wirelessly or via an Ethernet cable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found