GithubHelp home page GithubHelp logo

Get callback get fired twice about needle HOT 6 CLOSED

a70ma avatar a70ma commented on August 18, 2024
Get callback get fired twice

from needle.

Comments (6)

tomas avatar tomas commented on August 18, 2024

Holy shmoly. I'll take a look at this ASAP.

from needle.

tomas avatar tomas commented on August 18, 2024

I think the problem lies with the server responding with a Content-Length of 0 bytes. That makes the parse error occur at the socket level, not at the JSON.parse() level:

Error: Parse Error
    at Socket.socketOnData (http.js:1583:20)
    at TCP.onread (net.js:527:27)

I'm not sure how we should handle this. I could skip the error if its code equals 'HPE_INVALID_CONSTANT', and you would get an empty buffer as a response. What do you think?

from needle.

a70ma avatar a70ma commented on August 18, 2024

Personally i don't mind getting an error ( any error ) while i won't get the second callback it's fine.
But i'm not a fan of hardcoding stuff, better build a simple mechanism to keep track when a callback was fired ( like making callback = null or fired = true etc ) , because i'm not sure if HPE_INVALID_CONSTANT is the only case.
In the web scrapers world things are scary.

from needle.

tomas avatar tomas commented on August 18, 2024

Yeah, I know (been there). Needle's point is to make it easy for developers, so I guess we should handle this case in a better way. After all, what everyone cares for is the data, not if the data's full length matches what the Content-Length header says.

from needle.

tomas avatar tomas commented on August 18, 2024

On second thought, and after reading about the HPE_INVALID_CONSTANT error, we're not handling that error code because it may occur for other reasons as well, such as the response not having an HTTP header. I think it's too dangerous to not trigger this error if the HTTP parser raises it.

I just pushed an updated version that does check whether the callback was fired or not, though, so you shouldn't get the callback fired twice now. I'm closing this issue but feel free to reopen it if you spot any other weirdness. :)

from needle.

a70ma avatar a70ma commented on August 18, 2024

Thanks, i'll do that tomorrow.

from needle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.