Skip to content

RangeError when using EventSource with vendored dependencies #537

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

Closed
jraedisch opened this issue Oct 17, 2016 · 6 comments
Closed

RangeError when using EventSource with vendored dependencies #537

jraedisch opened this issue Oct 17, 2016 · 6 comments

Comments

@jraedisch
Copy link

package main

import (
    "github.com/gopherjs/gopherjs/js"
    "honnef.co/go/js/util"
)

func main() {
    println("initializing")
    es := js.Global.Get("EventSource").New("/events")
    et := util.EventTarget{Object: es}
    et.AddEventListener("message", false, listener)
}

func listener(obj *js.Object) {
    println(obj)
}

Will fail in $internalize case $kindStruct when GopherJS and js/util are vendored:

source.js:2051 Uncaught RangeError: Maximum call stack size exceeded
searchJsObject  @   source.js:2051
searchJsObject  @   source.js:2063
searchJsObject  @   source.js:2060
searchJsObject  @   source.js:2063
...

Without vendoring, everything works fine.

You can create a simple EventStream like this (in case you don't have one lying around):

package main

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

func main() {
    http.HandleFunc("/events", EventsHandler)
    log.Fatal(http.ListenAndServeTLS(":8081", "selfsigned.crt", "selfsigned.key", nil))
}

// EventsHandler returns a stream of timestamp messages.
func EventsHandler(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "text/event-stream")
    w.Header().Set("Cache-Control", "no-cache")
    w.Header().Set("Connection", "keep-alive")

    notify := w.(http.CloseNotifier).CloseNotify()
    conn := true
    go func() {
        <-notify
        conn = false
    }()

    for conn {
        fmt.Fprintf(w, "data: %s\n\n", time.Now())
        if f, ok := w.(http.Flusher); ok {
            f.Flush()
        } else {
            log.Println("no flush")
        }
        time.Sleep(2 * time.Second)
    }
    log.Println("conn closed")
}
@myitcv
Copy link
Member

myitcv commented Oct 17, 2016

Possible dupe of #415 @shurcooL?

@jraedisch
Copy link
Author

I forgot to mention that other GopherJS code works fine, so I do not think that it is an exact dup.

@dmitshur
Copy link
Member

dmitshur commented Oct 17, 2016

Yes, I think this is a duplicate of #415, since:

Will fail in $internalize case $kindStruct when GopherJS and js/util are vendored

Without vendoring, everything works fine.

Vendoring GopherJS is currently not supported and may manifest in various errors. #415 tracks the issue of supporting vendoring.

@dmitshur
Copy link
Member

@jraedisch, if that makes sense to you, let's close this issue for now. Once #415 is resolved, this should be resolved as well. If not, we can re-open it and investigate.

@jraedisch
Copy link
Author

jraedisch commented Oct 17, 2016

@shurcooL the issue isn't so much that vendoring is not supported, but that it may manifest in so many different ways, that other people might not find #415. Maybe a more descriptive error message or an info in the README.md would be helpful?

@dmitshur
Copy link
Member

that other people might not find #415. Maybe a more descriptive error message or an info in the README.md would be helpful?

Yes, fully agreed, we should resolve it partially by at least documenting that limitation in the README. A single sentence would be fine.

dmitshur added a commit that referenced this issue Oct 18, 2016
…ted.

GopherJS itself supports vendoring, but vendoring _it_ into your project
is currently not supported. Issue #415 tracks the progress on fixing that.

Helps #415.
Updates #537.
dmitshur added a commit that referenced this issue Oct 18, 2016
…ted.

GopherJS itself supports vendoring, but vendoring _it_ into your project
is currently not supported. Issue #415 tracks the progress on fixing that.

Helps #415.
Updates #537.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants