softprops / shiplift

🐳 🦀 rust interface for maneuvering docker containers
MIT License
624 stars 118 forks source link

BadRequest: "Bad parameter" #21

Closed themasch closed 3 years ago

themasch commented 8 years ago

I'm getting a Fault { code: BadRequest, message: "bad parameter" } on every request to docker.

Here a two complete backtraces, created by running the examples from master:

[masch@mark-laptop:~/code/rust/shiplift on master]
% sudo RUST_LOG=debug RUST_BACKTRACE=1 ./target/debug/examples/events
listening for events
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Fault { code: BadRequest, message: "bad parameter" }', ../src/libcore/result.rs:746
stack backtrace:
   1:     0x561838fb30b0 - sys::backtrace::tracing::imp::write::h3675b4f0ca767761Xcv
   2:     0x561838fb584b - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44519
   3:     0x561838fb54b8 - panicking::default_handler::h18faf4fbd296d909lSz
   4:     0x561838faa47c - sys_common::unwind::begin_unwind_inner::hfb5d07d6e405c6bbg1t
   5:     0x561838faa908 - sys_common::unwind::begin_unwind_fmt::h8b491a76ae84af35m0t
   6:     0x561838fb2661 - rust_begin_unwind
   7:     0x561838fe4e5f - panicking::panic_fmt::h98b8cbb286f5298alcM
   8:     0x561838e7b610 - result::unwrap_failed::h14728117271176524093
                        at ../src/libcore/macros.rs:29
   9:     0x561838e7b3b4 - result::Result<T, E>::unwrap::h15254061339421577925
                        at ../src/libcore/result.rs:687
  10:     0x561838e7a51a - main::hf27ff4eeae946ce8gaa
                        at examples/events.rs:8
  11:     0x561838fb5114 - sys_common::unwind::try::try_fn::h14622312129452522850
  12:     0x561838fb25eb - __rust_try
  13:     0x561838fb4bab - rt::lang_start::h0ba42f7a8c46a626rKz
  14:     0x561838e7d879 - main
  15:     0x7f2f8563661f - __libc_start_main
  16:     0x561838e7a268 - _start
  17:                0x0 - <unknown>
[masch@mark-laptop:~/code/rust/shiplift on master]
% sudo RUST_LOG=debug RUST_BACKTRACE=1 ./target/debug/examples/containers
DEBUG:hyper::http::h1: request line: Get "/containers/json" Http11
DEBUG:hyper::http::h1: headers=Headers { Host: ///var/run/docker.sock:0, }
DEBUG:hyper::client::response: version=Http11, status=BadRequest
DEBUG:hyper::client::response: headers=Headers { Connection: close, Content-Type: text/plain, }
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Fault { code: BadRequest, message: "bad parameter" }', ../src/libcore/result.rs:746
stack backtrace:
   1:     0x55e1a24fcab0 - sys::backtrace::tracing::imp::write::h3675b4f0ca767761Xcv
   2:     0x55e1a24ff24b - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44519
   3:     0x55e1a24feeb8 - panicking::default_handler::h18faf4fbd296d909lSz
   4:     0x55e1a24f321c - sys_common::unwind::begin_unwind_inner::hfb5d07d6e405c6bbg1t
   5:     0x55e1a24f36a8 - sys_common::unwind::begin_unwind_fmt::h8b491a76ae84af35m0t
   6:     0x55e1a24fc061 - rust_begin_unwind
   7:     0x55e1a252e98f - panicking::panic_fmt::h98b8cbb286f5298alcM
   8:     0x55e1a22dad14 - result::unwrap_failed::h17605680571608167188
                        at ../src/libcore/macros.rs:29
   9:     0x55e1a22daab0 - result::Result<T, E>::unwrap::h8036330443532157769
                        at ../src/libcore/result.rs:687
  10:     0x55e1a22d729d - main::h94c991ab960693d3haa
                        at examples/containers.rs:9
  11:     0x55e1a24feb14 - sys_common::unwind::try::try_fn::h14622312129452522850
  12:     0x55e1a24fbfeb - __rust_try
  13:     0x55e1a24fe5ab - rt::lang_start::h0ba42f7a8c46a626rKz
  14:     0x55e1a22dcf09 - main
  15:     0x7f13eff5361f - __libc_start_main
  16:     0x55e1a22d70a8 - _start
  17:                0x0 - <unknown>

I tried to debug it but wasn't lucky. I'm using docker 1.11.

Using curl works fine:

[masch@mark-laptop:~/code/rust/shiplift on master]
% sudo curl --unix-socket /var/run/docker.sock http:/containers/json -vvv 
*   Trying /var/run/docker.sock...
* Connected to http (/var/run/docker.sock) port 80 (#0)
> GET /containers/json HTTP/1.1
> Host: http
> User-Agent: curl/7.45.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Server: Docker/1.11.0 (linux)
< Date: Thu, 21 Jul 2016 20:26:27 GMT
< Content-Length: 3
< 
[]
* Connection #0 to host http left intact

Any Ideas on what I'm doing wrong?

Morsicus commented 8 years ago

Hi there,

It looks like our lib is not 100% compliant with docker 1.11 (API Version 1.23)

With docker 1.10, the example code works well.

I'm trying to understand what is going on.

themasch commented 8 years ago

Okay, sadly I can't (easily) downgrade to docker 1.10 on my dev box because it's not in the repository anymore.

[EDIT] I tried mirroring the request with curl and got this:

% sudo curl --unix-socket /var/run/docker.sock http:/containers/json -vvv -H"Host: ///var/run/docker.sock:0"                                                               101 ↵ ✹
*   Trying /var/run/docker.sock...
* Connected to http (/var/run/docker.sock) port 80 (#0)
> GET /containers/json HTTP/1.1
> Host: ///var/run/docker.sock:0
> User-Agent: curl/7.45.0
> Accept: */*
> 
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain
< Connection: close
< 
* Closing connection 0
400 Bad Request: malformed Host header

Seems like the Host HTTP-Header causes the problem. Specifing a host when using unix-socket doesn't make sense to me at all. Can the header be omitted?

[Edit2]: I think that is a ""bug"" in hyper: http://hyper.rs/hyper/v0.9.10/src/hyper/src/client/mod.rs.html#309 Its always sending a Host-Header. Can this be fixed in hyperlocal or do we need to open a ticket on hyper itself?

Morsicus commented 8 years ago

Indeed, it looks like a real problem :s.

First we need to see if we can remove the header from Hyperlocal. If we can't we will open a ticket on Hyper.

For your downgrade, it's strange. :s. What distribution are you using ?

themasch commented 8 years ago

I'm using gentoo.

I configured docker to listen to a tcp socket for further development. Will post a PR for some fixes regarding hostname/ip & port handling with http(s) connections soon.

r-darwish commented 7 years ago

I think this was fixed by 448ea95b4cbfe487501f79f150d87757d724bec8. Can you please try again?

softprops commented 7 years ago

I man I really missed this issue. http://doc.crates.io/specifying-dependencies.html#specifying-dependencies-from-git-repositories is how to test a git url dependency in your cargo build. I'm on vacation and away from my laptop. I'll try to publish recent fixes as soon as I can

shulcsm commented 7 years ago

If you could decide on concrete version or range we could pin endpoint to that and write serialization tests. I had a similar issue: this https://github.com/softprops/shiplift/blob/master/src/rep.rs#L152 is an array now. I'm pretty sure there are other issues.

softprops commented 7 years ago

I just published version 0.3.0 can you try that. I did need to make a few changes to what was on master to get things back up to speed.

I'm testing with what I think should be pretty close to the latest and greatest.

$ docker version
Client:
 Version:      1.13.0-rc3
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   4d92237
 Built:        Tue Dec  6 01:15:44 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.13.0-rc4
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   88862e7
 Built:        Sat Dec 17 01:34:17 2016
 OS/Arch:      linux/amd64
 Experimental: false

If you are still are having trouble can you comment with the output of docker version in this issue

shulcsm commented 7 years ago

Still an issue

Client:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:42:17 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:42:17 2016
 OS/Arch:      linux/amd64

This fixes things to me https://github.com/softprops/shiplift/pull/33

lowlevl commented 6 years ago

This seems fixed @softprops, can you confirm @themasch ?

elihunter173 commented 3 years ago

Is this issue still relevant?

themasch commented 3 years ago

@elihunter173 not for me.

elihunter173 commented 3 years ago

Alright, could you close the issue then please? (I don't have the perms to)