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

RequestInit::new() is hanging #41

Closed
OlegWasHere opened this issue Sep 12, 2021 · 5 comments · Fixed by #51
Closed

RequestInit::new() is hanging #41

OlegWasHere opened this issue Sep 12, 2021 · 5 comments · Fixed by #51

Comments

@OlegWasHere
Copy link

OlegWasHere commented Sep 12, 2021

Hi!

It seems like something's wrong with RequestInit::new(). Here is the simple code, it creates empty RequestInit and then returns empty response. And it stucks.

use worker::*;

mod utils;

fn log_request(req: &Request) {
    console_log!(
        "{} - [{}], located at: {:?}, within: {}",
        Date::now().to_string(),
        req.path(),
        req.cf().coordinates().unwrap_or_default(),
        req.cf().region().unwrap_or("unknown region".into())
    );
}

#[event(fetch)]
pub async fn main(req: Request, env: Env) -> Result<Response> {
    log_request(&req);

    utils::set_panic_hook();

    let _init = RequestInit::new(); // the code stucks here

    Response::empty()
}

And here's the logs from wrangler dev:

👂  Listening on http://127.0.0.1:8787
Sun Sep 12 2021 12:06:47 GMT+0000 (Coordinated Universal Time) - [/], located at: (59.8983, 30.2618), within: St.-Petersburg
Error: Worker exceeded CPU time limit. at line 0, col -2
{
  "exceptionDetails": {
    "columnNumber": -2,
    "exception": {
      "className": "Error",
      "description": "Error: Worker exceeded CPU time limit.",
      "preview": {
        "description": "Error: Worker exceeded CPU time limit.",
        "entries": null,
        "overflow": false,
        "properties": [],
        "subtype": "error",
        "type": "object"
      },
      "subtype": "error",
      "type": "object",
      "value": null
    },
    "lineNumber": 0,
    "text": "Uncaught (in response)",
    "url": "undefined"
  },
  "timestamp": 1631448407649
}
[2021-09-12 15:06:46] GET response-bot-dev.idebugger.workers.dev/ HTTP/1.1 503 Service Unavailable
@nilslice
Copy link
Contributor

Thank you for reporting this. RequestInit definitely needs some work, but it is interesting that it seems to be consuming so much CPU. Maybe it is recursively calling something. I will take a look.

@extraymond
Copy link

Thank you for reporting this. RequestInit definitely needs some work, but it is interesting that it seems to be consuming so much CPU. Maybe it is recursively calling something. I will take a look.

It's this line:

impl Default for RequestInit {
fn default() -> Self {
Self::new()
}
}

Request_init::default called Request_init::new which called Request_init::default recursively.

@OlegWasHere
Copy link
Author

I hope this will be fixed soon. AFAIK it's impossible to make POST requests without RequestInit. Is it so?

@nilslice
Copy link
Contributor

@OlegWasHere - I'm aiming to get a release out today which fixes this. However, if you don't need any Cloudflare-specific features for your outbound Request, then I'd try to use another HTTP client crate that works with wasm32 target, such as reqwest

@OlegWasHere
Copy link
Author

@nilslice Oh, thanks for clarifying! I didn't know that it's possible to use other HTTP clients. And thanks for the fix :)

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

Successfully merging a pull request may close this issue.

3 participants