My application runs just fine from my laptop (OSX). I’m trying to build a docker image to run my app based on alpine (edge) linux. The application (a http server) builds fine and runs but crashes when trying to process a http response:
Unhandled exception in spawn(name: d7eb4036): Invalid encoding: utf-8 (ArgumentError)
from /usr/lib/crystal/core/iconv.cr:29:35 in 'initialize'
from /usr/lib/crystal/core/iconv.cr:9:3 in 'new'
from /usr/lib/crystal/core/io/encoding.cr:61:16 in 'initialize'
from /usr/lib/crystal/core/io/encoding.cr:60:5 in 'new'
from /usr/lib/crystal/core/io.cr:496:7 in 'decoder'
from /usr/lib/crystal/core/io.cr:545:10 in 'gets_to_end'
from /usr/lib/crystal/core/http/client/response.cr:81:15 in 'consume_body_io'
from /usr/lib/crystal/core/http/client/response.cr:105:9 in 'from_io?'
from /usr/lib/crystal/core/http/client.cr:562:5 in 'exec_internal_single'
from /usr/lib/crystal/core/http/client.cr:548:5 in 'exec_internal'
from /usr/lib/crystal/core/http/client.cr:544:5 in 'exec'
from /usr/lib/crystal/core/http/client.cr:666:5 in 'exec'
from /usr/lib/crystal/core/http/client.cr:370:3 in 'post'
:
I’m guessing I’m missing some libraries. Here’s the apk command from my Dockerfile:
Same error here, trying to build a static executable from the latest alpine docker image, but http/client throws an exception about utf-8 encoding. Any idea about which apk would be missing ? Been trying to investigate the changes in musl-libc, but I found nothing.
if that fails, try with “UTF-8” and see if that works. If that works it means that iconv changed what they accept for valid encodings, maybe they dropped support for “utf-8” and they only accept “UTF-8”, I don’t know.
Could someone try this on their alpine docker image?
The fix might be to always send encodings uppercased.
I guess you’ll need to debug the application to find out what’s getting to Iconv.new and why it’s failing.
This is easy: you can modify iconv.cr directly in your Crystal distribution, or reopen it, copy the initialize method in your program and add debug info there (puts). Same goes with whatever you get from the http client.
It would be helpful to know which HTTP endpoint you are hitting too.
But all of this can be solved with debugging the code.