wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.71k stars 325 forks source link

faketime cargo fails #402

Closed mraszyk closed 2 years ago

mraszyk commented 2 years ago

faketime cannot be used with cargo (the Rust package manager):

$ cargo new hello
     Created binary (application) `hello` package
$ cd hello/
$ faketime -1minutes cargo build --release
error: process didn't exit successfully: `rustc -vV` (signal: 11, SIGSEGV: invalid memory reference)

I'm running faketime 0.9.8 on a 64-bit Ubuntu:

$ uname -a
Linux lenovo 5.15.0-40-generic #43-Ubuntu SMP Wed Jun 15 12:54:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
wolfcw commented 2 years ago

I'm having a hard time reproducing this (cargo 1.42.1, rustc 1.41.1).

Any chance you could try with a more recent version of libfaketime? v0.9.8 is from 2019 and eventually there were relevant changes already.

If it still crashes, it'd be good to have some more debugging information on which system call it happened on.

mraszyk commented 2 years ago

Thank you for looking into this issue!

faketime v0.9.8 is what I got installed using apt install faketime on Ubuntu 22.04. After manully building and installing faketime from sources, the above command hangs. Interestingly, it does not hang when invoking cargo with faketime again after having actually built the sources without faketime:

$ faketime --version

faketime: Version 0.9.10
For usage information please use 'faketime --help'.
$ faketime -1minutes cargo build --release
^C
$ cargo build --release
   Compiling hello v0.1.0 (/home/martin/hello)
    Finished release [optimized] target(s) in 0.64s
$ faketime -1minutes cargo build --release
    Finished release [optimized] target(s) in 0.00s

and I could successfully run this faketime also on this simple example

$ cat a.cpp
#include <cstdio>
#include <ctime>

int main() {
  printf("%ld\n", time(NULL));

  return 0;
}
$ g++ -o a a.cpp
$ ./a
1656566818
$ faketime -1minutes ./a
1656566762
wolfcw commented 2 years ago

Thanks for trying this out. That's already progress. :-)

Could you please tell me whether libfaketime's make test hangs as well on your system? If so, it'd be good to know your glibc version. It might then get you a step further to add FORCE_MONOTONIC_FIX to libfaketime's compile flags (in src/Makefile), and if that doesn't do the trick, additionally set the environment variable FAKETIME_DONT_FAKE_MONOTONIC to 1.

Usually hard-working maintainers per distro choose the correct compile-time parameters. I don't know why Ubuntu is still stuck to v0.9.8. Let's find out how to get it to work there, and eventually we can trigger some update process for Ubuntu then.

mraszyk commented 2 years ago

I could successfully execute make test without any additional setup.

mraszyk commented 2 years ago

Is anybody working on this issue?

mraszyk commented 2 years ago

Might be related to this: https://github.com/wolfcw/libfaketime/issues/130

mraszyk commented 2 years ago

I can confirm that this issue is due to jemalloc, building Rust from source with jemalloc = false in config.toml solves the issue. I still wonder if it was possible to link libfaketime statically so that jemalloc from Rust and malloc from libfaketime do not interfere?

wolfcw commented 2 years ago

Thanks for tracing it down to jemalloc.

I recommend to find a solution that either works without libfaketime or without jemalloc. jemalloc & libfaketime is a really long-standing issue and there are no known satisfying workarounds.

If you want to dig deeper, you might want to try adding some basic error handling in the places where jemalloc calls time-related system functions. I still think the problem could be solved on jemalloc's side.

mraszyk commented 2 years ago

Is the issue reported with jemalloc? Anyway, for now I'll use rustc compiled without jemalloc.

wolfcw commented 2 years ago

closing this as duplicate of #130 , which is still open for discussion and suggestions.