poco icon indicating copy to clipboard operation
poco copied to clipboard

Poco::Net::HTTPClientSession does not work with a Poco::Net::SocketAddress with family UNIX_LOCAL

Open adalton opened this issue 6 years ago • 3 comments

Expected behavior

I'm trying to use Poco::Net::HTTPClientSession to communicate with Docker, which exposes an HTTP interface over a UNIX domain socket. I would expect HTTPClientSession to be SocketAddress agnostic, and for it to be able to talk HTTP over whatever socket the caller supplies.

Actual behavior

The constructor for HTTPClientSession calls host() on the supplied SocketAddress: https://github.com/pocoproject/poco/blob/develop/Net/src/HTTPClientSession.cpp#L72

Unfortunately, host() throws and InvalidAccessException: https://github.com/pocoproject/poco/blob/develop/Net/include/Poco/Net/SocketAddressImpl.h#L211

Steps to reproduce the problem

The following program will trigger the problem:

#include <string>
#include <Poco/Net/HTTPClientSession.h>

int main()
{
    std::string socketFilename = "/path/to/some/domain.socket";
    Poco::Net::HTTPClientSession session(
        Poco::Net::SocketAddress(Poco::Net::SocketAddress::UNIX_LOCAL,
                                 socketFilename));

        return 0;
}

Compiled with:

$ g++ -ggdb ex.cc -lPocoNet

Running this results in:

$ ./a.out
terminate called after throwing an instance of 'Poco::InvalidAccessException'
  what():  Invalid access
Aborted (core dumped)

The backtrace looks like:

(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff6d71121 in __GI_abort () at abort.c:79
#2  0x00007ffff7757fd5 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libstdc++.so.6
#3  0x00007ffff7755be6 in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libstdc++.so.6
#4  0x00007ffff7755c31 in std::terminate() () from /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libstdc++.so.6
#5  0x00007ffff7755e73 in __cxa_throw () from /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libstdc++.so.6
#6  0x00007ffff7b888bc in Poco::Net::Impl::LocalSocketAddressImpl::host (this=<optimized out>)
    at /usr/src/debug/dev-libs/poco-1.9.0/poco-poco-1.9.0-release/Net/include/Poco/Net/SocketAddressImpl.h:212
#7  0x00007ffff7b85a25 in Poco::Net::SocketAddress::host (this=this@entry=0x7fffffffd838)
    at /usr/src/debug/dev-libs/poco-1.9.0/poco-poco-1.9.0-release/Net/src/SocketAddress.cpp:208
#8  0x00007ffff7b2eac5 in Poco::Net::HTTPClientSession::HTTPClientSession (this=0x7fffffffd860, address=...)
    at /usr/src/debug/dev-libs/poco-1.9.0/poco-poco-1.9.0-release/Net/src/HTTPClientSession.cpp:67
#9  0x0000555555555934 in main () at ex.cc:15

POCO version

$ equery --quiet list poco
dev-libs/poco-1.9.0

Compiler and version

$ g++ --version
g++ (Gentoo 7.3.0-r3 p1.4) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Operating system and version

$ cat /etc/os-release 
NAME=Gentoo
ID=gentoo
PRETTY_NAME="Gentoo/Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.gentoo.org/"
SUPPORT_URL="https://www.gentoo.org/support/"
BUG_REPORT_URL="https://bugs.gentoo.org/"

Other relevant information

N/A

adalton avatar Jan 09 '19 15:01 adalton

Still valid with 1.9.4

cheese avatar Jun 24 '20 07:06 cheese

I also encountered this bug. I also found a workaround - create StreamSocket and pass it to HTTPClientSession:

Poco::Net::SocketAddress socketAddress(Poco::Net::SocketAddress::UNIX_LOCAL, socketPath);
Poco::Net::StreamSocket socket(socketAddress);
Poco::Net::HTTPClientSession session(socket);

sirzooro avatar Nov 03 '20 14:11 sirzooro

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Jun 22 '22 03:06 github-actions[bot]

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Nov 24 '23 02:11 github-actions[bot]