Solving “getaddrinfo() thread failed to start”

Curl-logoIf you download files onto your system using PHP, Yum, RPM, or other tools, there’s a good chance curl is involved, be it part of a library (such as PHP’s curl extension and the Guzzle HTTP client) or called as its own program.

While curl is very reliable, there’s a specific scenario that can trip it up: lack of threading in a job. IBM i PASE provides a version of curl that speeds up common tasks like DNS lookups by using additional threads. When threading support is not available, however, curl fails.

Threads are allowed by default in most PASE sessions (for example, SSH or QP2TERM), but other job types, such as QSH sessions and batch jobs, disable threads by default. If threads are not enabled when you use curl, you’ll get messages like:

getaddrinfo() thread failed to start

Don’t worry! Nothing’s wrong with curl or your code. You just need to allow multi-threading in your job, like so:

  • Set the environment variable QIBM_MULTI_THREADED to Y before starting any program that runs curl. This can be done at whatever scope you feel is appropriate; for example, it can be put in a shell (interactively or in a script) before you start the program.
    • Example: before invoking QSH, call the CL command ADDENVVAR ENVVAR(QIBM_MULTI_THREADED) VALUE(Y) REPLACE(*YES).
    • QP2SHELL does not support threads. Change it to QSH with QIBM_MULTI_THREADED.
  • Alternatively, start the job with the ALWMLTTHD parameter set to *YES.

After you do this, curl shouldn’t have any problems.

This post was based on the curl documentation for IBM i-specific notes.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.