Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

prevent silent errors in daemon mode#10007

Merged
5chdn merged 16 commits into
masterfrom
daemonize
Feb 1, 2019
Merged

prevent silent errors in daemon mode#10007
5chdn merged 16 commits into
masterfrom
daemonize

Conversation

@seunlanlege
Copy link
Copy Markdown
Member

@seunlanlege seunlanlege commented Dec 3, 2018

This PR replaces daemonize from crates.io, with a custom daemonize

The custom daemonize pipes the daemon's STDOUT/STDERR to the parent process, after parity-ethereum successfully starts the daemon process detaches from the parent and the parent exits.

TODO:

  • Update Java bindings

@parity-cla-bot
Copy link
Copy Markdown

It looks like @seunlanlege signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@seunlanlege seunlanlege requested review from dvdplm, ordian and tomaka and removed request for dvdplm and tomaka December 3, 2018 15:44
@seunlanlege seunlanlege added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Dec 3, 2018
Copy link
Copy Markdown
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

It fails silently on my linux laptop (need to investigate further).
Open questions:

  1. Do we want to maintain our custom fork (or rather reimplementation) of daemonize?
  2. If we do, should it be placed in util/daemonize? (E.g. why not in a separate repo)

Comment thread parity/main.rs Outdated
Comment thread parity/main.rs Outdated
Comment thread util/daemonize/src/lib.rs Outdated
Comment thread util/daemonize/src/lib.rs Outdated
Comment thread util/daemonize/src/lib.rs Outdated
Comment thread util/daemonize/src/lib.rs Outdated
@5chdn 5chdn added this to the 2.3 milestone Dec 4, 2018
@niklasad1
Copy link
Copy Markdown
Collaborator

If we want to maintain this it should go in a separate repo preferable forked under the parity org as we have done with other forks such as ring, rocksdb etc

@seunlanlege
Copy link
Copy Markdown
Member Author

not sure why the c++ example isn't compiling @5chdn

Copy link
Copy Markdown
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

The c++ example is failing because the interface for start has changed, clib needs to be updated here.

The code looks good in general, but I still think we should move it to a separate repository (and maybe publish to crates.io), because it seems like a general improvement (modulo missing features) over daemonize, which others would probably want to use (and it seems like daemonize is unmaintained atm). Also we need tests like these and it would be nice to run them on linux and macOS.

Comment thread parity/main.rs Outdated
Comment thread parity/main.rs Outdated
Comment thread parity/lib.rs Outdated
Comment thread util/daemonize/src/lib.rs Outdated
Comment thread util/daemonize/src/lib.rs Outdated
Comment thread Cargo.toml Outdated
Comment thread parity/lib.rs
pub fn start<Cr, Rr>(conf: Configuration, on_client_rq: Cr, on_updater_rq: Rr) -> Result<ExecutionAction, String>
pub fn start<Cr, Rr>(
conf: Configuration,
logger: Arc<RotatingLogger>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This breaks the C-bindings in parity-clib you need to update them accordingly

Copy link
Copy Markdown
Contributor

@tomaka tomaka Dec 27, 2018

Choose a reason for hiding this comment

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

The difficult part of #8574 (and the reason why it wasn't done immediately when parity-clib was created) is that ideally the RotatingLogger wouldn't be exposed in the API.

However I guess we can ignore the problem in the name of "meh, who cares", and open another issue for that specific thing instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're not exposing RotatingLogger in C API, we expose only Logger params struct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mentioned "when parity-clib was created", because the Rust lib and the C library were created at the same time.

The logging system is unfortunately a global variable, and thus it shouldn't be the job of a library to set it.
The consequence is that if a program wants to use parity-as-a-library, they cannot setup their own logging compatible with the log crate.
An ideal world, it is main.rs that would setup the logging and that's it. The C library would have an independent function (not tied to parity, just like parity_set_panic_hook is totally independent as well) that sets up the Rust logging and explicitly mentions in its documentation that this applies to the log Rust crate as a whole.

@niklasad1
Copy link
Copy Markdown
Collaborator

@seunlanlege The changes you did parity::start breaks the C bindings and you need to add a logger object there both in parity.h and in main.cpp. I can help you if you are not familiar with C/C++

@seunlanlege
Copy link
Copy Markdown
Member Author

@niklasad1 please do, thanks.

@seunlanlege
Copy link
Copy Markdown
Member Author

moved the implementation to here

@ordian
Copy link
Copy Markdown
Member

ordian commented Dec 10, 2018

FYI: The naming convention for rust crates from the api-guidelines:

Crate names should not use -rs or -rust as a suffix or prefix. Every crate is Rust! It serves no purpose to remind users of this constantly.

Could you remove util/daemonize, also clib logger API needs to be sorted out.

@niklasad1 niklasad1 force-pushed the daemonize branch 3 times, most recently from 8a0125e to df07353 Compare December 11, 2018 21:47
Comment thread parity-clib/parity.h Outdated
///
/// Returns 0 on success, and non-zero on error.
int parity_start(const ParityParams* params, void** out);
int parity_start(const ParityParams* params, Logger logger, void** out);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well, we could also pass Logger as a pointer to be uniform but I decided to pass it by value to reduce the possibility for deref NULL in the library. However, it will requre 4 words of memory instead of 1 word and it will probably not fit in the registers and need to pushed on the stack (assuming not inlined)

It is still possible to deref NULL if a null pointer is passed as string with len != 0

Comment thread parity-clib/src/lib.rs Outdated
let cfg: &ParityParams = &*cfg;

let mode = {
if logger.mode_len == 0 {
Copy link
Copy Markdown
Collaborator

@niklasad1 niklasad1 Dec 12, 2018

Choose a reason for hiding this comment

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

Make sure an empty string is not constructed!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're not using this check in parity_config_from_cli, I think it's safe since mem::align_of::<u8> == 1 and also String::from_utf8(slice.to_owned()) does not allocate if the slice.is_empty().

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, it is redundant thus it should be removed

However, when it comes to log-file we need the check because an empty string as file name will be a run-time error/panic

Comment thread parity-clib/src/lib.rs Outdated
};

let file = {
if logger.file_len == 0 {
Copy link
Copy Markdown
Collaborator

@niklasad1 niklasad1 Dec 12, 2018

Choose a reason for hiding this comment

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

Make sure an empty string is not constructed!

@seunlanlege
Copy link
Copy Markdown
Member Author

@5chdn I can't sign in to gitlab, could you please restart the android build?

@niklasad1
Copy link
Copy Markdown
Collaborator

@seunlanlege I restarted it but it looks like you need to bump parity-daemonize to get the latest changes

@seunlanlege
Copy link
Copy Markdown
Member Author

looks like alls good here

Copy link
Copy Markdown
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment thread parity-clib/src/lib.rs Outdated
let cfg: &ParityParams = &*cfg;

let mode = {
if logger.mode_len == 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're not using this check in parity_config_from_cli, I think it's safe since mem::align_of::<u8> == 1 and also String::from_utf8(slice.to_owned()) does not allocate if the slice.is_empty().

Comment thread parity/main.rs Outdated
@tomaka
Copy link
Copy Markdown
Contributor

tomaka commented Jan 28, 2019

I'm fine with leaving it as it is, because doing it properly requires a lot of work.
I opened #10252.

@5chdn 5chdn added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A3-stale 🍃 Pull request did not receive any updates in a long time. No review needed at this stage. Close it. A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jan 29, 2019
@5chdn 5chdn merged commit 0f9b221 into master Feb 1, 2019
@5chdn 5chdn deleted the daemonize branch February 1, 2019 18:31
This was referenced Feb 3, 2019
ordian added a commit that referenced this pull request Feb 3, 2019
* master:
  Fix Windows build (#10284)
  Don't run the CPP example on CI (#10285)
  Additional tests for uint deserialization. (#10279)
  prevent silent errors in daemon mode (#10007)
ordian added a commit that referenced this pull request Apr 5, 2019
* master:
  Fix Windows build (#10284)
  Don't run the CPP example on CI (#10285)
  Additional tests for uint deserialization. (#10279)
  prevent silent errors in daemon mode (#10007)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. M4-core ⛓ Core client code / Rust.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants