Skip to content

Locale should default to C / Posix Environment #4147

Closed

Description

@itoffshore

Busybox does not use locales - bitcoin should set a default C / Posix environment. The following locale error:

EXCEPTION: St13runtime_error       
locale::facet::_S_create_c_locale name not valid       
bitcoin in AppInit()       

terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid

Can be fixed with the following patch #4147 (comment)

The above patch is almost identical to the patch I proposed for Namecoin to fix this issue (Windows builds are unaffected):namecoin/namecoin-legacy#72 (comment)

Activity

  1. laanwj commented on May 7, 2014

    @laanwj
    Member

    Overwriting LC_ALL with a fixed value is quite an ugly solution (busybox may not use locales, but we do).

    Isn't there something more specific that can be done about the boost error?

  2. itoffshore commented on May 7, 2014

    @itoffshore
    ContributorAuthor

    I tried catching the error & then setting the environment without success

  3. sipa commented on May 7, 2014

    @sipa
    Member

    Is this caused by the use time_input_facet in DecodeDumpTime in rpcdump.cpp?

  4. itoffshore commented on May 7, 2014

    @itoffshore
    ContributorAuthor

    This error is thrown in AppInit() - setting LC_ALL in AppInit2() did not fix the problem

  5. luke-jr commented on May 7, 2014

    @luke-jr
    Contributor

    If your system doesn't use locales, then setlocale(any, "" or NULL) should simply return "C", and setlocale(any, anything else) should return NULL. If that is causing problems in boost or bitcoind, those problems should be fixed rather than forcing the "C" locale.

  6. itoffshore commented on May 7, 2014

    @itoffshore
    ContributorAuthor

    this was in bitcoinrpc.cpp in the namecoin sources but it did not force a C locale

    string locale(setlocale(LC_TIME, NULL)); 
    
  7. laanwj commented on May 7, 2014

    @laanwj
    Member

    You keep talking about namecoin.

    Do we, in the current master version of bitcoin, have anything that generates this error?

    If so, where is it raised? Where does the exception originate from? It must be some usage of boost. Can we avoid that, maybe by passing in our own locale object instead of using the system one?

    Edit: I see we indeed use setlocale here: https://github.com/bitcoin/bitcoin/blob/master/src/rpcprotocol.cpp#L52 . That's not thread-safe at all. But it appears that the exception is raised at at start-up, so it cannot be caused by that.

  8. itoffshore commented on May 7, 2014

    @itoffshore
    ContributorAuthor

    The exact error in Bitcoin is:

    terminate called after throwing an instance of 'std::runtime_error'
      what():  locale::facet::_S_create_c_locale name not valid
    Aborted
    
  9. sipa commented on May 7, 2014

    @sipa
    Member

    And which code throws it?

  10. itoffshore commented on May 7, 2014

    @itoffshore
    ContributorAuthor

    just running 'bitcoind --help' is enough to generate the error - any command will generate the same error on a machine without locales.

    A default C locale should be set.

  11. sipa commented on May 7, 2014

    @sipa
    Member

    I don't want an ugly workaround hack unless we know what code throws this error, and that there is no other way to avoid the problem.

  12. laanwj commented on May 7, 2014

    @laanwj
    Member

    I don't understand how this happens in the first place: boost raises this error if it cannot find the selected locale.
    As @luke-jr says, the "C" locale is selected by default if you have not set another locale (so if LC_* is not set).
    Where does it get this information from? Can you show your environment?

  13. itoffshore commented on May 7, 2014

    @itoffshore
    ContributorAuthor
    uclibc [~/packages/testing/x86]$ printenv
    PAGER=less
    PS1=\[\e[1;32m\]\h [\[\e[0m\]\w\[\e[1;32m\]]$ \[\e[0m\]
    TERM=xterm
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    LANG=en_US.UTF-8
    SHELL=/bin/ash
    CHARSET=UTF-8
    EDITOR=nano
    

    A C environment is not being set by default on bitcoin or namecoin - as already noted 'setlocale(LC_TIME, NULL)' does not force a C environment on Busybox (Alpine Linux)

  14. laanwj commented on May 7, 2014

    @laanwj
    Member

    LANG=en_US.UTF-8

    This may be the culprit if you don't have the en_US locale.
    Can you try undefining it?

  15. luke-jr commented on May 7, 2014

    @luke-jr
    Contributor

    It seems the way most software handles unknown locales is to ignore them. We should do the same...

  16. 22 remaining items

  17. jl2035 commented on Oct 27, 2014

    @jl2035
    Contributor

    yeah that's it. everytime i login i first have to run 'export LC_ALL=C' and than bitcoind works

  18. itoffshore commented on Oct 27, 2014

    @itoffshore
    ContributorAuthor

    you could also put the command in ~/.bashrc or in /etc/profile or /etc/default/locale

    without exporting LC_ALL - what does 'echo $LC_ALL' or 'locale' give for LC_ALL ? (maybe something else on your system is setting it to an incompatible value for Bitcoin) - you would need to log off & on again to test this.

  19. jl2035 commented on Oct 29, 2014

    @jl2035
    Contributor

    thanks.

    "LC_ALL" is empty for some reason..

  20. luke-jr commented on Oct 29, 2014

    @luke-jr
    Contributor

    It's normal for LC_ALL to be unset.

  21. jl2035 commented on Oct 30, 2014

    @jl2035
    Contributor

    ok.
    it is working with LC_ALL set to "C", so I guess that's ok for me.. i also don't need this node for long..

  22. adattudos commented on Apr 16, 2015

    @adattudos

    This is still an open issue in 0.10.1rc2 even though 0.10.0 was fine in the same environment:

    EXCEPTION: St13runtime_error       
    locale::facet::_S_create_c_locale name not valid       
    bitcoin in AppInit()       
    
    terminate called after throwing an instance of 'std::runtime_error'
      what():  locale::facet::_S_create_c_locale name not valid
    Aborted (core dumped)
    
  23. itoffshore commented on May 6, 2015

    @itoffshore
    ContributorAuthor

    Testing 0.10.1 there is no longer any environment regression.

    0.10.1 should also be patched as shown here to fix a segfault introduced in 0.10

  24. Diapolo commented on May 25, 2015

    @Diapolo

    @laanwj Not sure where to post, but AFAIK some change to locale handling was revert, which reintroduces a crash when chaning -txindex and aborting or when trying to abort Qt startup during init phase in splash screen... too bad this is unfixed again :-/.

  25. laanwj commented on Feb 16, 2016

    @laanwj
    Member

    Is this issue fixed or still present in 0.12 / master?

    There have been more changes to this code since, so I suppose it is, but as the locale initialization is complex voodoo code there could always be an edge case.

  26. itoffshore commented on Feb 16, 2016

    @itoffshore
    ContributorAuthor

    This issue has been fixed since 0.10.1 in Alpine Linux & also with 0.11.x too.

    I will try building 0.12

  27. laanwj commented on Feb 16, 2016

    @laanwj
    Member

    Oh! If it was fixed back then I doubt it has come back now. Just wonder why the issue was never closed then.
    But if you want to try on 0.12 just in case, thanks :)

  28. jl2035 commented on Feb 16, 2016

    @jl2035
    Contributor

    I no longer run a full node, so I never reported back.

  29. itoffshore commented on Feb 16, 2016

    @itoffshore
    ContributorAuthor

    0.12 is fine too - this issue can be closed

  30. locked as resolved and limited conversation to collaborators on Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions