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

Fix for pihole-FTL test #1067

Merged
merged 8 commits into from
Feb 20, 2021
Merged

Fix for pihole-FTL test #1067

merged 8 commits into from
Feb 20, 2021

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Feb 17, 2021

By submitting this pull request, I confirm the following:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?:

10


Fix a few issues revealed when checking why pihole-FTL test doesn't work as expected:

  1. The test option is currently broken: It immediately terminates all FTL components (threads surrounding the resolver, etc.), however, it did not terminate the resolver itself leading to an attempt to kill the resolver in the docker container.
  2. The log file lock should be shared among processes to ensure we cannot outpace forks (which may result in a log deadlock). This may fix dhcp-script not being called in v5.1.2 #906 as byproduct of our improvements in here
  3. We should not detach threads we want to cancel explicitly later on when terminating
  4. Ensure we clean up behind us on crashes and fatal errors (such as port 53 not available, dnsmasq config errors, etc.)
  5. Improve process-already-running detection (better formatting)

This fixes #1063 and #1064

… up at process termination anyway.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…hared memory

Signed-off-by: DL6ER <dl6er@dl6er.de>
…g to shared memory locks. Other forks may want to log as well.

Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER
Copy link
Member Author

DL6ER commented Feb 18, 2021

Confirmed working by original reporter in #1063

@DL6ER DL6ER added the PR: Approval Required Open Pull Request, needs approval label Feb 18, 2021
@dschaper dschaper added PR: Approved Open Pull Request, Approved by required number of reviewers and removed PR: Approval Required Open Pull Request, needs approval labels Feb 19, 2021
@dschaper
Copy link
Member

Any changes needed or suggested for the Docker image?

@DL6ER
Copy link
Member Author

DL6ER commented Feb 19, 2021

Not needed but we should get rid of the kill -9 now being obsolete after we fixed the test command here.

@PromoFaux already added TODOs:

but I am not in the position to make a PR as I have never used the Pi-hole docker container and wouldn't know if getting rid of them without replacement is the right thing to do. I'm however sure that KILL is always wrong, TERM should work as well and is to be preferred (we can clean up behind up, store the last queries into the database, etc.).

@Beanow
Copy link

Beanow commented Feb 19, 2021

Yes, I think we can at least step down to TERM.
The one that's in 20-start.sh can probably removed completely.

Instead, in bash_functions.sh we might use a blocking test, rather than anticipating a daemon to kill.

pihole-FTL -f test was something I tested at #1065 and does indeed behave differently.
Though we might want to look into how to handle it's logs (which like -f / no-daemon go to stdio).

# Perhaps wrap it to be quiet unless it fails?
pihole-FTL -f test &> /var/logs/pihole-FTL.test.log
RES=$?
if [[ $RET != 0 ]]; then
    cat /var/logs/pihole-FTL.test.log
fi

One thing I would suggest looking into though is this:
For starting the process a cleanup has been added https://github.com/pi-hole/docker-pi-hole/blob/20cd9c3abf95e00d2d1920ba432e2a0272c42942/s6/debian-root/etc/services.d/pihole-FTL/run#L4-L6

This makes sense, because the service will to endlessly try to restart in case it fails to start initially. It's a great feature to have to make it low maintenance and self-healing, even if it isn't the most elegant in implementation details.

Because in a sense, we're doing a very similar cleanup as we'd want FTL to do on a clean shutdown, perhaps this is redundant code and we could use a pihole-FTL cleanup or pihole-FTL --force no-daemon argument so that knowledge about how to clean up doesn't go out of sync?

@DL6ER DL6ER merged commit e8cb3f6 into development Feb 20, 2021
@DL6ER DL6ER deleted the fix/test_crash branch February 20, 2021 20:51
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-ftl-v5-8-web-v5-5-and-core-v5-3-released/46237/1

DistractionRectangle added a commit to DistractionRectangle/docker-pi-hole that referenced this pull request Jul 25, 2021
Since piholeFTL test properly spins down it's no longer
necessary to kill it. He's dead Jim

Merge pi-hole#300, added `piholeFTL test` to the startup sequence to
replace dnsmasq as a dependency for validate_env and gravity.sh.
kill -9 was kept as a work around to a standing issue that
`piholeFTL test` didn't spin down on it's own. This was fixed
in pi-hole/FTL#1067, landed on Apr 14 2021 and confirmed
working, as evinced by pi-hole#834 which was filed the same day it
that fix landed.

Signed-off-by: D.Rect <48034372+DistractionRectangle@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix PR: Approved Open Pull Request, Approved by required number of reviewers
Projects
None yet
4 participants