container.training icon indicating copy to clipboard operation
container.training copied to clipboard

WEBUI & hasher app not going through

Open eliassal opened this issue 1 year ago • 10 comments

Hi Jermoe, the videos regarding "Deploying and Scaling Microservices with Docker and Kubernetes" are really fantastic. and I learned a lot. However, when I try to run Docker compose up in bitcoins directory, all containers start and work fine except the webui one which errors as follows (myabe because latest images used are not compatible with code, I am really not expert in node nor in ruby)

Hasher error

hasher-1  | == Sinatra (v3.2.0) has taken the stage on 80 for development with backup from Thin
hasher-1  | 127.0.0.1 - - [03/Jan/2024:13:00:33 +0000] "GET / HTTP/1.1" 200 31 0.0026
worker-1  | INFO:__main__:0 units of work done, updating hash counter
worker-1  | ERROR:__main__:In work loop:
worker-1  | Traceback (most recent call last):
worker-1  |   File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 203, in _new_conn
worker-1  |     sock = connection.create_connection(
worker-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1  |   File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection

then webui error

webui-1   | /node_modules/redis/dist/index.js:31
webui-1   |     ...bloom_1.default,
webui-1   |     ^^^
webui-1   |
webui-1   | SyntaxError: Unexpected token ...
webui-1   |     at exports.runInThisContext (vm.js:53:16)
webui-1   |     at Module._compile (module.js:373:25)
webui-1   |     at Object.Module._extensions..js (module.js:416:10)

Thanks for your help

eliassal avatar Jan 03 '24 13:01 eliassal

Hi!

I have checked the code and it should work fine without any modifications.

Regarding the worker, I suggest waiting for a few minutes to see if it reconnects automatically and succeeds. Sometimes, the end of the traceback can provide more useful information about the issue.

Similarly, for the hasher, I believe there might be additional details in the rest of the traceback that could help you understand the problem better.

jpetazzo avatar Jan 04 '24 17:01 jpetazzo

Merci Jerome. This morning, I came across the other session at https://www.youtube.com/watch?v=broMJgUmPG8&list=PLBAFXs0YjviJwCoxSUkUPhsSxDJzpZbJd&index=49 and using the tag v0.1

kubectl create deployment rng --image=dockercoins/rng:v0.1
kubectl create deployment hasher --image=dockercoins/hasher:v0.1
kubectl create deployment worker --image=dockercoins/worker:v0.1
kubectl create deployment webui --image=dockercoins/webui:v0.1

all pods were up and running and I was able to access the webui. I tried again the docker compose up version, still getting the same errors, on ubuntu as well as Dockerdesktop on windows. Thnaks for all thos wonderful videos you made available, ils sont vraiement utiles :-)

eliassal avatar Jan 04 '24 18:01 eliassal

When using docker compose up version, Yes the hasher starts working after sometime but not webui

eliassal avatar Jan 04 '24 18:01 eliassal

Note that the webui can show some error logs, but it might still work (i.e. if you connect to it with a web browser, you will see the graph).

jpetazzo avatar Jan 05 '24 10:01 jpetazzo

@jpetazzo I confirm that I'm also seeing a lot of errors on startup of the various containers but things appear to work as expected from the WebUI. If I find the time this weekend, I'll try to refactor the Docker Compose.

conradwt avatar Jan 05 '24 11:01 conradwt

Hi!

The errors are expected :-)

This is because the various components are connecting immediately to their dependencies - for instance, worker tries to connect immediately to rng, hasher, redis, before these dependencies have started. The initial connection attempt fails (because the dependency isn't up and running yet). But there is a (very crude) retry logic, so the next connection attempt typically succeeds, and then everything is fine.

I haven't fixed the code because when I teach a class, I use this as an example, and we discuss how it can be addressed (e.g. with healthchecks, init containers, etc.)

jpetazzo avatar Jan 05 '24 12:01 jpetazzo

@conradwt as I said, all containers start fine and can see communications between them except in my case webui which fails to start (it exits) with the error

webui-1   | /node_modules/redis/dist/index.js:31
webui-1   |     ...bloom_1.default,
webui-1   |     ^^^
webui-1   |
webui-1   | SyntaxError: Unexpected token ...

eliassal avatar Jan 05 '24 12:01 eliassal

@eliassal I'm not able to reproduce the issue that you're seeing and I have tried it on both my Intel and Apple Silicon MacBook Pros.

conradwt avatar Jan 05 '24 12:01 conradwt

@jpetazzo You make a very good point here because a distributed application tends to start its services in a nondeterministic order. I definitely need to review adding healthchecks for my K8s pods.

conradwt avatar Jan 05 '24 12:01 conradwt

@conradwt well I cant add anything more than the error message webui is sending. If you like I can let you see the error by yourself if you accpet through a visio session :-)

eliassal avatar Jan 05 '24 14:01 eliassal