title: Unable to access Google Cloud IoT Core via Proxy
body: <p>I have created an application in Go that connects device and Google Cloud IoT Core via MQTT.
  The device side is under Proxy environment and I want to connect to IoT Core through Proxy.</p>
  <p>I am using this library <a href="https://github.com/eclipse/paho.mqtt.golang" rel="nofollow noreferrer">paho.mqtt.golang</a> version 1.4.1 (I have raised an <a href="https://github.com/eclipse/paho.mqtt.golang/issues/611" rel="nofollow noreferrer">issue</a> in github too).</p>
  <p>I am trying to connect to Google Cloud IoT Core ( <code>mqtt.googleapis.com:443</code> ) via PROXY using the environment variables <code>HTTP_PROXY</code> and <code>HTTPS_PROXY</code>, but I get a <code>ConnectionTimeout</code> and cannot establish a connection.</p>
  <pre><code>// Application Log
  // ssl
  Sep  2 09:39:51 : [DEBUG] [client]   Connect()
  Sep  2 09:39:51 : [DEBUG] [store]    memorystore initialized
  Sep  2 09:39:51 : [DEBUG] [client]   about to write new connect msg
  Sep  2 09:40:21 : [ERROR] [client]   dial tcp 64.233.188.206:443: i/o timeout
  Sep  2 09:40:21 : [WARN]  [client]   failed to connect to broker, trying next
  Sep  2 09:40:21 : [ERROR] [client]   Failed to connect to a broker
  Sep  2 09:40:21 : [DEBUG] [store]    memorystore closed
  
  // wss
  Sep  2 09:57:13 : [DEBUG] [client]   Connect()
  Sep  2 09:57:13 : [DEBUG] [store]    memorystore initialized
  Sep  2 09:57:13 : [DEBUG] [client]   about to write new connect msg
  Sep  2 09:57:15 : [ERROR] [client]   unexpected EOF
  Sep  2 09:57:15 : [WARN]  [client]   failed to connect to broker, trying next
  Sep  2 09:57:15 : [ERROR] [client]   Failed to connect to a broker
  Sep  2 09:57:15 : [DEBUG] [store]    memorystore closed
  
  </code></pre>
  <p>The command <code>openssl s_client -proxy XXXX -connect mqtt.googleapis.com:443</code> succeeds, confirming no network problems. I have also confirmed that the environment variable values are readable on the go program.</p>
  <p>I am trying to connect from the following code, is there a problem?</p>
  <pre class="lang-golang prettyprint-override"><code>// MQTT Publisher
  func MqttPublisher(message string) error {
  // ...
  
      opts := mqtt.NewClientOptions().
          AddBroker(&quot;ssl://mqtt.googleapis.com:443&quot;).
          SetClientID(client_id).
          SetUsername(&quot;unused&quot;).
          SetTLSConfig(&amp;tls.Config{MinVersion: tls.VersionTLS12}).
          SetPassword(pass).
          SetProtocolVersion(4). // Use MQTT 3.1.1
  
      conn := mqtt.NewClient(opts)
      log.Println(&quot;Connecting...&quot;)
  
      // connect to GCP Cloud IoT Core
      tok := conn.Connect()
      if err := tok.Error(); err != nil {
          log.Println(&quot;tok.Error():1&quot;)
          return err
      }
      if !tok.WaitTimeout(time.Second * 10) {
          // Error occurs here
          return fmt.Errorf(&quot;connection Timeout&quot;)
      }
      if err := tok.Error(); err != nil {
          log.Println(&quot;tok.Error():2&quot;)
          return err
      }
  // ...
  }
  </code></pre>