Skip to content

Tinygo crashes on http.Client{}.Do() with Timeout #58

@Darckfast

Description

@Darckfast

client.Do() a crashes When creating a new http.Client{} with timeout

net/http/client.go

Lines 433 to 439 in 1026408

func (c *Client) Do(req *Request) (*Response, error) {
if c.Transport != nil {
return c.Transport.RoundTrip(req)
}
return c.do(req)
}

if !deadline.IsZero() && didTimeout() {

Seems like the when creating a client the transport is nil, which causes the .Do() to use tls.Dial, which returns an error, but the func didTimeout is never initialized like on net/http in Go https://github.com/golang/go/blob/d00c67f297ef6f2cb2cd0e9aae59fa3936bb7eca/src/net/http/client.go#L264

Error

❯ ./app
panic: runtime error at 0x000000000024bd02: nil pointer dereference
fish: Job 1, './app' terminated by signal SIGABRT (Abort)

POC

package main

import (
	"log"
	"net/http"
	"time"
)

func main() {
	c := http.Client{
		Timeout: 2 * time.Second,
	}

	rs, _ := http.NewRequest("GET", "https://google.com", nil)
	r, e := c.Do(rs)

	if e != nil {
		log.Println(e)
	} else {
		log.Println(r.Status)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions