Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: addition of waku_api/rest/builder.nim and reduce app.nim #2623

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

Ivansete-status
Copy link
Collaborator

@Ivansete-status Ivansete-status commented Apr 23, 2024

Description

Extract some REST logic from app.nim, aiming for simplify app.nim a little.
I will submit a couple of similar PRs simplifying app.nim.

note: this has the same goal as #2610 but I decided to submit a different one just to keep the original one as a temporary reference. I will drop the initial PR once this gets merged

Copy link

github-actions bot commented Apr 23, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2623-rln-v2

Built from 14f1673

Copy link

github-actions bot commented Apr 23, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2623-rln-v1

Built from 14f1673

@Ivansete-status Ivansete-status marked this pull request as ready for review April 23, 2024 20:49
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check conf.rest properly in all cases, it not worth to spare.

if app.restServer.isSome():
await app.restServer.get().stop()
if app.conf.rest:
await app.restServer.stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really see where app.restServer is assigned?
So when it stops it will result in segfault:

/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(203) wakunode2
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncengine.nim(1210) runForever
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncengine.nim(1031) poll
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/ioselects/ioselectors_epoll.nim(643) selectInto2
../sysdeps/unix/sysv/linux/epoll_wait.c(30) epoll_wait
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(175) handleCtrlC
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(165) asyncStopper
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncfutures.nim(382) futureContinue
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(166) asyncStopper
/home/nzp/dev/status/nwaku-second/waku/factory/app.nim(320) stop
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncfutures.nim(382) futureContinue
/home/nzp/dev/status/nwaku-second/waku/factory/app.nim(321) stop
/home/nzp/dev/status/nwaku-second/waku/waku_api/rest/server.nim(191) stop
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncfutures.nim(382) futureContinue
/home/nzp/dev/status/nwaku-second/waku/waku_api/rest/server.nim(193) stop
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(194) handleSigsegv
Segmentation fault

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really see where app.restServer is assigned? So when it stops it will result in segfault:

/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(203) wakunode2
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncengine.nim(1210) runForever
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncengine.nim(1031) poll
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/ioselects/ioselectors_epoll.nim(643) selectInto2
../sysdeps/unix/sysv/linux/epoll_wait.c(30) epoll_wait
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(175) handleCtrlC
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(165) asyncStopper
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncfutures.nim(382) futureContinue
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(166) asyncStopper
/home/nzp/dev/status/nwaku-second/waku/factory/app.nim(320) stop
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncfutures.nim(382) futureContinue
/home/nzp/dev/status/nwaku-second/waku/factory/app.nim(321) stop
/home/nzp/dev/status/nwaku-second/waku/waku_api/rest/server.nim(191) stop
/home/nzp/dev/status/nwaku-second/vendor/nim-chronos/chronos/internal/asyncfutures.nim(382) futureContinue
/home/nzp/dev/status/nwaku-second/waku/waku_api/rest/server.nim(193) stop
/home/nzp/dev/status/nwaku-second/apps/wakunode2/wakunode2.nim(194) handleSigsegv
Segmentation fault

Wow! Thanks for it!
I tried to tackle that in d448dd6

qq: how did you force that stop ? Very interesting validation :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was easy, run with --rest=true and run node than press ctrl-c to finish.


let address = conf.restAddress
let port = Port(conf.restPort + conf.portsShift)
let server =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in case conf.rest is false we shall not create the restServer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in case conf.rest is false we shall not create the restServer.

Good point and thanks for the comment! Nevertheless, I'm trying to respect the current implementation where we always create, at least, one restServer when calling startRestServerEsentials:

let restServerRes = startRestServerEsentials(nodeHealthMonitor, conf)

let server =

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why to run an http service and open port while it is explicitly told on cli not to do so?
I would not expose any port and consume resource in case it is not needed. WDYT?

Copy link
Contributor

@gabrielmer gabrielmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks beautiful :)
Thank you!

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is great!!!!

if app.restServer.isSome():
await app.restServer.get().stop()
if app.conf.rest:
await app.restServer.stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was easy, run with --rest=true and run node than press ctrl-c to finish.


let address = conf.restAddress
let port = Port(conf.restPort + conf.portsShift)
let server =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why to run an http service and open port while it is explicitly told on cli not to do so?
I would not expose any port and consume resource in case it is not needed. WDYT?

@Ivansete-status Ivansete-status merged commit b28207a into master Apr 24, 2024
13 of 15 checks passed
@Ivansete-status Ivansete-status deleted the refactor-discovery-2 branch April 24, 2024 13:59
@Ivansete-status
Copy link
Collaborator Author

@NagyZoltanPeter - what do you mean in these questions?

But why to run an http service and open port while it is explicitly told on cli not to do so?
I would not expose any port and consume resource in case it is not needed. WDYT?

@NagyZoltanPeter
Copy link
Contributor

@NagyZoltanPeter - what do you mean in these questions?

But why to run an http service and open port while it is explicitly told on cli not to do so?
I would not expose any port and consume resource in case it is not needed. WDYT?

@Ivansete-status We discussed in dm and you fixed. It was just about not to start restServer if configured --rest=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants