1

I've tried to see if anyone else if having this problem, but I haven't found anything online yet. Does anything in this code looks like I'm invoking boost incorrectly?

This code works when I am logged into the machine that is starting the TCP server, but fails when no one is logged in. I stripped the code down to only look at the boost asio logic.

//create _acceptor, which will eventually listen for incomming connections, asynchronously
_acceptor = boost::shared_ptr<tcp::acceptor>(new tcp::acceptor(*_io_service));
_acceptor->open(tcp::endpoint(tcp::v4(), _port).protocol());
_acceptor->set_option(tcp::acceptor::reuse_address(false));

//omitted logic find a port that is open
_acceptor->bind(tcp::endpoint(tcp::v4(), _port));

//omitted error handling logic if open port not found

//Start listening for incoming connections asynchronously.
_acceptor->listen();

sslSocketPtr ssl_socket(sslSocketPtr(new ssl::stream<ip::tcp::socket>(*_io_service, _sslContext)));
_acceptor->async_accept(ssl_socket->lowest_layer(),
    boost::bind(&TCPServer::handle_sslAccept, shared_from_this(), boost::asio::placeholders::error, ssl_socket));

When no one is logged into the machine, the ssl_socket constructor throws the exception: "static_mutex: Access is denied".

If I define BOOST_ASIO_ENABLE_OLD_SSL the code works correctly, but I think that may be contributing to another bug in my code. So I am trying to use the latest SSL logic from Boost.

Any help would be appreciated!

2
  • "when no one is logged into the machine" do you start the process in a different way? Also, what platform are you running this on (I can't believe you didn't mention this essential bit of information in the post...)
    – sehe
    Dec 22, 2014 at 19:54
  • Sorry for not including the scenario and environment. This is running on Windows 7. The process is launched from a remote machine connecting to a daemon which launches another program as the remote user (with their credentials). This final program is the one having an issue with the TCP Server. Dec 22, 2014 at 20:21

1 Answer 1

2

I'm going to assume from the symptoms that you run on Windows.

On windows, static_mutex is implemented as a named (interprocess) mutex and gets "opened" using CreateMutexW:

If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the existing object, GetLastError returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling thread is not granted ownership. However, if the caller has limited access rights, the function will fail with ERROR_ACCESS_DENIED and the caller should use the OpenMutex function.

As you can see you don't have the required permissions. However, you could still have this working if the mutex is always created by a privileged process. In that case you could modify the code that opens an existing named mutex with OpenMutex as the documentation hints.

It's likely easier to run the process under a user that has the required permissions thought

2
  • That sounds like a reasonable explanation. This seems like it would be a bug in Boost since I do not call CreateMutex or OpenMutex directly. Would you agree with that? Dec 22, 2014 at 20:30
  • @Snowman6286 I would not agree with that. The fact that the library implements features that require permissions is not - per se - a bug. You could ask the library devs though, they will be able to have a more authoritative answer
    – sehe
    Dec 22, 2014 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.