Skip to content

Unable to use unix-socket connections #1252

Description

@craether-nbb

Describe the bug
MongoDB is able to use unix sockets, next to regular IPs. But when trying to use this socket (following the documentation) for the PMM MongoDB Exporter (running at the same container), it fails to handle the socket URI.
PMM itself seems to have no issue with defining a socket, just the MongoDB exporter.
It's throwing 3 exceptions when trying to use sockets. (See Logs section)

To Reproduce
Steps to reproduce the behavior:

  • Launch a MongoDB and configure the required pmm user
  • Configure the PMM agent
  • Add the mongodb_export using the following command: pmm-admin add mongodb --socket="/tmp/mongodb-27017.sock" --username="pmm" --password="pmm" --query-source="profiler" --replication-set="rs0" --server-insecure-tls --skip-connection-check

Attached you'll find an example stack of a MongoDB and PMM configured to use sockets, throwing the exceptions.
pmm_socket_issue.zip

Expected behavior
As documented at MongoDB itself and the PMM MongoDB Exporter help (CLI), it should be possible to use sockets instead of IPs to connect the exporter with the MongoDB.

Logs

  1. First "invalid URL escape"

    time="2026-03-04T11:56:48.782+00:00" level=error msg="time=2026-03-04T11:56:48.782Z level=ERROR source=server.go:181 msg=\"Unable to parse provided address as url\" address=\"mongodb://***:***@%2Ftmp%2Fmongodb-27017.sock/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000\" error=\"parse \\\"mongodb://***:***@%2Ftmp%2Fmongodb-27017.sock/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000\\\": invalid URL escape \\\"%2F\\\"\"" agentID=bfcd3f7f-2a9e-4dcc-9d93-d8a937a2bfe3 component=agent-process type=mongodb_exporter
    

    In this case the url.Parse() seems to be unable to handle the encoded socket URL.
    Source of the exception is server.go:181

  2. Second "invalid URL escape"

    time="2026-03-04T11:57:23.384+00:00" level=warning msg="Failed to get instance ID for action: failed to parse DSN: parse \"mongodb://pmm:pmm@%2Ftmp%2Fmongodb-27017.sock/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000\": invalid URL escape \"%2F\"" component=runner
    
  3. "Broken pipe"

    {"t":{"$date":"2026-03-04T11:57:23.407+00:00"},"s":"I",  "c":"EXECUTOR", "id":22989,   "ctx":"conn38","msg":"Error sending response to client. Ending connection from remote","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"futurize :: caused by :: Broken pipe"},"remote":"anonymous unix socket:27017","connectionId":38}}
    

    One of these exceptions during the initial startup is ok and occures no matter of using a unix socket or the localhost IP, but all the other occurences are related to using a unix socket.

Environment

  • Hostsystem: MacOS 26.3 on a M1 MacBook Pro
  • Docker 4.62.0
  • MongoDB 8.0
  • PMM admin version: 3.6.0

Additional context

pmm-admin add mongodb --help

Usage: pmm-admin add mongodb [<name> [<address>]] [flags]

Add MongoDB to monitoring

[...]

Flags:
[...]
    --socket=STRING                                Path to socket
[...]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions