Upgrading compiler causes application to hang or segfault in Vec::push


I recently dusted off playform and ran rustup. To my surprise, it started hanging. It turns out that upgrading the compiler past rustc 1.20.0-nightly (3610a70ce 2017-07-05) (to the next nightly or the latest nightly) causes a hang in one of my calls to Vec::push in a release build. If I build in debug mode, I get a segfault.

By reverting commits and building the rust compiler, it seems as though the offending commit is

commit 1685c9298685f73db4fe890c1ed27b22408aaad7
Merge: 4d526e0d14 695dee063b
Author: bors <bors@rust-lang.org>
Date:   Thu Jul 6 00:16:16 2017 +0000

    Auto merge of #42727 - alexcrichton:allocators-new, r=eddyb
    rustc: Implement the #[global_allocator] attribute
    This PR is an implementation of [RFC 1974] which specifies a new method of
    defining a global allocator for a program. This obsoletes the old
    `#![allocator]` attribute and also removes support for it.
    [RFC 1974]: https://github.com/rust-lang/rfcs/pull/1974
    The new `#[global_allocator]` attribute solves many issues encountered with the
    `#![allocator]` attribute such as composition and restrictions on the crate
    graph itself. The compiler now has much more control over the ABI of the
    allocator and how it's implemented, allowing much more freedom in terms of how
    this feature is implemented.
    cc #27389

Building and installing rustc before this commit shows old behavior in playform, and building with this commit shows the new broken behavior.

This isn’t a huge commit but it does seem to touch code that has some say in allocation behavior, but I’m not familiar enough to say anything more insightful than that. If someone has any hunches or ideas for experiments I can run, that would be much appreciated.

I’m working on getting a minimal repro with minimal package dependencies but playform is a big beast with, shall we say, less-than-careful allocation so it will take a little time. The minimal repro branch is at https://github.com/bfops/playform/tree/debug-hanging.


That’s a fairly old compiler - any particular reason you’re interested in it?


I clarified the original post to say that upgrading to 07-06 or any later compiler causes this behavior.


Ah ok. A github issue will likely be a better avenue to report this.


I found the “bug” and the “fix”.

The commit I referenced in the original post changed the syntax for selecting an allocator. Playform used to opt out of jemalloc in favor of the system allocator (I don’t remember why, but presumably because of exactly this deadlock deep in a jemalloc mutex). When the syntax changed, it silently switched back to jemalloc, with no warning about the obsolete syntax.


Nice - thanks for following up. So is there a lurking bug in jemalloc then? Does playform have any of its own unsafe code that could mess with the allocator?


While I am not skilled enough to comment on the black magic of allocator tuning, the lack of a warning sounds like a legitimate usability bug. Are you following that up in the rust repo issues?


bjorn3 figured out that I was misusing Vec and making jemalloc angry.