Coder Social home page Coder Social logo

http_test.ts about deno_std HOT 8 CLOSED

denoland avatar denoland commented on May 2, 2024 3
http_test.ts

from deno_std.

Comments (8)

ry avatar ry commented on May 2, 2024 4

Hey - sorry for the late reply to this. http.ts is only half-implemented, as you can tell. It needs someone (probably me) to dig in and complete it. Help welcome - but otherwise you'll have to wait a few weeks. Ultimately we'll probably use a native http parser - this was added so we can benchmark what sort of overhead parsing in pure JS has (also just as some example code for people to look at)

from deno_std.

justjavac avatar justjavac commented on May 2, 2024 1

When using a browser to access, 2 requests were sent at the same time

GET / HTTP/1.1
GET /favicon.ico HTTP/1.1

For some reason (probably a bug), deno has not received EOF, cause Conn to not close. When using curl, can always receive EOF, so c.close() has been invoked.

from deno_std.

 avatar commented on May 2, 2024

Works in Firefox for me. Does not work in curl or wrk for me.

from deno_std.

FrankFang avatar FrankFang commented on May 2, 2024

It works in Chrome for me, but not in curl.

Steps to reproduce:

  1. deno http_test.ts
  2. curl http://127.0.0.1:8090 (you get a response)
  3. open Chrome, access http://127.0.0.1:8090 (you get a response)
  4. curl http://127.0.0.1:8090 (no response!)

from deno_std.

justjavac avatar justjavac commented on May 2, 2024

This server may only accept one link from a user agent.

  1. deno http_test.ts -D

    ...
    listening on http://0.0.0.0:8000/
    Deno requests network access to "listen". Grant? [yN] y
    DEBUG RS - msg_from_js Listen sync true
    DEBUG RS - resource lookup 3
    DEBUG RS - msg_from_js Accept sync false
    
  2. open Chrome, visit

    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 0 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Read sync false
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 0 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Write sync false
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Read sync false
    DEBUG RS - loop process - 1 events, 0.000s
    
  3. refresh it

    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 0 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Write sync false
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Read sync false
    DEBUG RS - loop process - 1 events, 0.000s
    
  4. open Firefox, visit

    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 0 events, 0.000s
    

    The program is suspended.

  5. refresh the webpage in Chrome again

    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 0 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Write sync false
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - msg_from_js Read sync false
    DEBUG RS - loop process - 1 events, 0.000s
    

    It still works.

  6. Waiting for a long time

    DEBUG RS - loop process - 1 events, 0.000s
    DEBUG RS - resource lookup 4
    DEBUG RS - dropping I/O source: 1
    DEBUG RS - loop process - 0 events, 0.000s
    DEBUG RS - msg_from_js Close sync true
    ConnectionAborted: 你的主机中的软件中止了一个已建立的连接。 (os error 10053)
    	at maybeError (deno/js/errors.ts:38:12)
    	at handleAsyncMsgFromRust (deno/js/dispatch.ts:27:17)
    

My system is Chinese, so the error message is also Chinese. I don't know what the English information is. I will simply translate it:

你的主机中的软件中止了一个已建立的连接。

The software in your host has aborted an established connection.

from deno_std.

FrankFang avatar FrankFang commented on May 2, 2024

@justjavac try curl http://127.0.0.1:8090/ & curl http://127.0.0.1:8090/favicon.ico

from deno_std.

justjavac avatar justjavac commented on May 2, 2024

I add some log-code, in Chrome, c.close() has indeed NOT been invoked, and listener.accept() has NOT been invoked too.

Maybe Chrome uses a socket connection pool, both requests use the same socket.

I generate a NetLog dump file.

url http://127.0.0.1:8000:

...
t=1007 [st=0]     +SOCKET_POOL  [dt=1]
t=1008 [st=1]        SOCKET_POOL_BOUND_TO_CONNECT_JOB
                     --> source_dependency = 55197 (TRANSPORT_CONNECT_JOB)
t=1008 [st=1]        SOCKET_POOL_BOUND_TO_SOCKET
                     --> source_dependency = 55198 (SOCKET)
...

url http://127.0.0.1:8000//favicon.ico:

t=1064 [st=0]     +SOCKET_POOL  [dt=0]
t=1064 [st=0]        SOCKET_POOL_REUSED_AN_EXISTING_SOCKET  <--- HERE
                     --> idle_ms = 53
t=1064 [st=0]        SOCKET_POOL_BOUND_TO_SOCKET
                     --> source_dependency = 55198 (SOCKET)

SOCKET_POOL_REUSED_AN_EXISTING_SOCKET.


I tried curl -H 'Connection: keep-alive', but there is no such error like Chrome.

from deno_std.

zhmushan avatar zhmushan commented on May 2, 2024

@justjavac u are right.
when i use browser access the url, the connection cannot be closed properly.

the following code seems to be working fine

import { serveConn } from './net/http'
import { listen } from 'deno'
;(async () => {
  const addr = '0.0.0.0:8000'
  const listener = listen('tcp', addr)
  console.log('listening on', addr)
  while (true) {
    const conn = await listener.accept()
    const res = await serveConn(conn).next()
    await res.value.respond({ body: new TextEncoder().encode('Hello\n') })
    conn.close()
  }
})()

from deno_std.

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.