Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Unable to connect in proxy environment! #394

Closed
iAmSKU opened this issue Jan 2, 2020 · 6 comments
Closed

[Question] Unable to connect in proxy environment! #394

iAmSKU opened this issue Jan 2, 2020 · 6 comments

Comments

@iAmSKU
Copy link

iAmSKU commented Jan 2, 2020

As per the documentation it says:
"If the client is running behind a corporate http/https proxy then the following environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY are taken into account when establishing the connection."

But unfortunately same is not working for my usecase:

Application Logs:
Starting...
http_proxy: 198.134.0.10:4800
https_proxy: 198.134.0.10:4800
no_proxy: localhost,127.0.0.1
Inside connect block.
[client] Connect()
[store] memorystore initialized
[client] about to write new connect msg
[client] dial tcp 35.156.164.229:8883: i/o timeout
[client] Failed to connect to a broker
[store] memorystore closed
[Network Error : dial tcp 35.156.164.229:8883: i/o timeout]

I have tried to force fully set the proxy to "http://198.134.0.10:4800" instead of "198.134.0.10:4800", but it does not worked.

With non proxy environment its connecting with out any issue:
Application Logs:

Starting...
http_proxy: 198.134.0.10:4800
https_proxy: 198.134.0.10:4800
no_proxy: localhost,127.0.0.1
Inside connect block.
[client] Connect()
[store] memorystore initialized
[client] about to write new connect msg
[client] socket connected to broker
[client] Using MQTT 3.1.1 protocol
[net] connect started
[net] received connack
[client] client is connected
[client] exit startClient

Any suggestion or working example, what i am missing for the proxy environment?

Or do I need to create a custom socket for the proxy environment?

@iAmSKU iAmSKU changed the title Unable to connect in proxy environment! [Question] Unable to connect in proxy environment! Jan 2, 2020
@MattBrittan
Copy link
Contributor

What version of the package are you using? Support for proxies (and the comment you referenced in the readme) was added in pull #322 which was committed on 21 Jun 2019. The latest release is 1.2.0 (19 Apr 2019) so if you are using that the proxy support is not included. If you are not using modules then you are probably using the latest code; but if you are using modules then you will be using 1.2.0 by default (run go get github.com/eclipse/paho.mqtt.golang@master to get the latest code).

Having said that the full content of the paragraph from the documentation that you refer to is:

The library also supports using MQTT over websockets by using the ws:// (unsecure) or wss:// (secure) prefix in the URI. If the client is running behind a corporate http/https proxy then the following environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY are taken into account when establishing the connection.

So this relates to MQTT over websockets (ws/wss) but as your code is attempting to connect via port 8883 (MQTT over TLS) I am assuming that you are using tcps (and not wss)? I don't think that its possible to proxy MQTT, other then MQTT over websockets, via an http/https proxy (they are different protocols). It may be possible via a SOCKS proxy but support for this would need to be added.

@iAmSKU
Copy link
Author

iAmSKU commented Jan 3, 2020

Thanks MattBrittan for quick answer...

I have recently started using the library (1 month back) so I assume I will have latest changes in place.

Yes I am using 8883(or 1883) ports for the communication which required TCP based communication, earlier I was using java based solution there I need to implement custom socket for the same.

But yes as you are saying the proxy support is only for the ws/wss then I can try the solution with wss and meanwhile can think on the custom socks proxy for the TCP.

Just for curiosity, does any plan to support proxy for the TCP (8883 TLS security)?

@MattBrittan
Copy link
Contributor

I have recently started using the library so I assume I will have latest changes in place

If you are using go modules then it will automatically get the highest version (meaning 1.2.0) but there have been quite a few changes since the last release (including the change I referenced earlier).

Just for curiosity, does any plan to support proxy for the TCP (8883 TLS security)?

Its something that I think would be pretty simple to implement (golang.org/x/net/proxy includes support for SOCKS5) however I'm not aware of any plans to implement this (most changes are made by users who need the feature).

@MattBrittan
Copy link
Contributor

Closing due to age/inactivity. Please feel free to reopen if this issue is occurring with the current release.

@amir-khassaia
Copy link

Just an FYI, to clarify this somewhat potentially confusing issue to help out others in the same situation.

It's possible to work with proxies better by supporting connection tunneling offered by HTTP/CONNECT for compatible proxies as defined in https://tools.ietf.org/html/rfc7231#section-4.3.6.

This works by having the compliant proxy transparently relaying the data and the client issues the connect just writes the data to the proxy without needing to know much more.
This is already provided by other paho implementations I believe, so should be reasonably straight forward to add for Golang too.

As a POC I attached a possible patch to make it work against mqtt.googleapis.com

http_connect.zip

@MattBrittan
Copy link
Contributor

@amir-khassaia thanks for your comment; it may be useful for someone referring to this issue in the future. However if you wish to submit a patch then please make a pull request (I'd also suggest raising a new issue stating the problem you are attempting to solve).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants