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

Several fixes #1872

Merged
merged 4 commits into from
Dec 10, 2024
Merged

Several fixes #1872

merged 4 commits into from
Dec 10, 2024

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Dec 10, 2024

  • url.searchParams parameter should reflect the changes in toString()
const url = new URL('http://example.com/?a=b');
url.searchParams.set('a', 'c');
console.log(url.toString()); // http://example.com/?a=c
  • Fix IPV6 parsing in `URL`;

new URL('http://[::1]') should parse the host as `[::1]` not `::1`.

  • fetch now handles parsed IPV6 URL instances correctly
const url = new URL('http://[::1]:4444');
fetch(url) // This was throwing `ENOTFOUND`
  • Promises passed to ctx.waitUntil was not blocking Symbol.asyncDispose method
import { createServerAdapter } from '@whatwg-node/server';

const deferred = Promise.withResolvers();

const adapter = createServerAdapter((req, ctx) => {
    ctx.waitUntil(deferred.promise);
    return new Response('Hello, world!');
});

const res = await adapter.fetch('http://example.com');
console.assert(res.status === 200);
console.assert(await res.text() === 'Hello, world!');

let disposed = false;
adapter[Symbol.asyncDispose]().then(() => {
    disposed = true;
});

console.assert(!disposed);

deferred.resolve();

console.assert(disposed);

Also closes #1801

@ardatan ardatan changed the title fix(node-fetch/URL): parse IPV6 hostnames correctly in \URL\, and also reflect changes in \toString\ when \searchParams\ modified fix(node-fetch/URL): parse IPV6 hostnames correctly in URL, and also reflect changes in toString when searchParams modified Dec 10, 2024
Copy link
Contributor

github-actions bot commented Dec 10, 2024

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@whatwg-node/node-fetch 0.7.5-alpha-20241210211414-d3ba0200610c3de61aea13ae4383d2db8ad54ac2 npm ↗︎ unpkg ↗︎
@whatwg-node/server 0.9.61-alpha-20241210211414-d3ba0200610c3de61aea13ae4383d2db8ad54ac2 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Dec 10, 2024

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=139.432029 min=12     med=139     max=199     p(90)=163     p(95)=167    
     data_received..................: 23 MB  764 kB/s
     data_sent......................: 15 MB  495 kB/s
     http_req_blocked...............: avg=2.21µs     min=652ns  med=1.4µs   max=11.59ms p(90)=2.01µs  p(95)=2.33µs 
     http_req_connecting............: avg=252ns      min=0s     med=0s      max=3.07ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=19.95ms    min=2.78ms med=19.2ms  max=1.07s   p(90)=25.15ms p(95)=27.91ms
       { expected_response:true }...: avg=19.95ms    min=2.78ms med=19.2ms  max=1.07s   p(90)=25.15ms p(95)=27.91ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 149784
     http_req_receiving.............: avg=35.1µs     min=8.75µs med=23.39µs max=20.41ms p(90)=39.25µs p(95)=47.94µs
     http_req_sending...............: avg=11.27µs    min=3.19µs med=6.65µs  max=19.41ms p(90)=9.9µs   p(95)=14.44µs
     http_req_tls_handshaking.......: avg=0s         min=0s     med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=19.91ms    min=2.75ms med=19.17ms max=1.07s   p(90)=25.1ms  p(95)=27.8ms 
     http_reqs......................: 149784 4992.135561/s
     iteration_duration.............: avg=40.02ms    min=8.69ms med=38.38ms max=1.09s   p(90)=45.27ms p(95)=50.03ms
     iterations.....................: 74863  2495.101242/s
     vus............................: 90     min=90        max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Dec 10, 2024

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 221724      ✗ 0     
     data_received..................: 22 MB   743 kB/s
     data_sent......................: 8.9 MB  296 kB/s
     http_req_blocked...............: avg=1.35µs   min=842ns    med=1.16µs   max=175.96µs p(90)=1.86µs   p(95)=2.03µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=116.54µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=209.69µs min=155.83µs med=196.52µs max=49.23ms  p(90)=222.96µs p(95)=233.4µs 
       { expected_response:true }...: avg=209.69µs min=155.83µs med=196.52µs max=49.23ms  p(90)=222.96µs p(95)=233.4µs 
     http_req_failed................: 0.00%   ✓ 0           ✗ 110862
     http_req_receiving.............: avg=25.07µs  min=13.69µs  med=23.82µs  max=814.6µs  p(90)=30.64µs  p(95)=32.83µs 
     http_req_sending...............: avg=6.06µs   min=3.89µs   med=5.3µs    max=403.15µs p(90)=7.96µs   p(95)=8.5µs   
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=178.55µs min=130.38µs med=165.16µs max=49.14ms  p(90)=188.49µs p(95)=198.19µs
     http_reqs......................: 110862  3695.254184/s
     iteration_duration.............: avg=266.2µs  min=208.82µs med=252.1µs  max=49.38ms  p(90)=282.16µs p(95)=295.61µs
     iterations.....................: 110862  3695.254184/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Dec 10, 2024

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=140.59248 min=103     med=141     max=196      p(90)=159     p(95)=163    
     data_received..................: 22 MB  737 kB/s
     data_sent......................: 14 MB  472 kB/s
     http_req_blocked...............: avg=3.96µs    min=652ns   med=1.35µs  max=7.37ms   p(90)=2µs     p(95)=2.28µs 
     http_req_connecting............: avg=2.16µs    min=0s      med=0s      max=7.3ms    p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=20.69ms   min=3.97ms  med=20.02ms max=491.26ms p(90)=26.13ms p(95)=29.42ms
       { expected_response:true }...: avg=20.69ms   min=3.97ms  med=20.02ms max=491.26ms p(90)=26.13ms p(95)=29.42ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 144461
     http_req_receiving.............: avg=35.35µs   min=9.43µs  med=23.58µs max=27.52ms  p(90)=38.67µs p(95)=46.28µs
     http_req_sending...............: avg=11.79µs   min=3.4µs   med=6.18µs  max=20.24ms  p(90)=9.77µs  p(95)=14.18µs
     http_req_tls_handshaking.......: avg=0s        min=0s      med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=20.65ms   min=3.94ms  med=19.98ms max=491.19ms p(90)=26.08ms p(95)=29.34ms
     http_reqs......................: 144461 4814.345795/s
     iteration_duration.............: avg=41.5ms    min=12.35ms med=39.8ms  max=526.58ms p(90)=48.2ms  p(95)=52.82ms
     iterations.....................: 72210  2406.489709/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Dec 10, 2024

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 298386      ✗ 0     
     data_received..................: 29 MB   980 kB/s
     data_sent......................: 12 MB   398 kB/s
     http_req_blocked...............: avg=1.39µs   min=812ns    med=1.19µs   max=271.38µs p(90)=1.88µs   p(95)=2.05µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=119.42µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=139.5µs  min=90.73µs  med=134.2µs  max=7.63ms   p(90)=155.52µs p(95)=161.89µs
       { expected_response:true }...: avg=139.5µs  min=90.73µs  med=134.2µs  max=7.63ms   p(90)=155.52µs p(95)=161.89µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 149193
     http_req_receiving.............: avg=24.51µs  min=12.16µs  med=23.31µs  max=7.5ms    p(90)=30.44µs  p(95)=32.52µs 
     http_req_sending...............: avg=6.28µs   min=4.02µs   med=5.48µs   max=2.01ms   p(90)=8.09µs   p(95)=8.64µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=108.69µs min=67.23µs  med=103.03µs max=6.96ms   p(90)=121.18µs p(95)=126.38µs
     http_reqs......................: 149193  4972.914031/s
     iteration_duration.............: avg=196.67µs min=138.88µs med=190.48µs max=7.72ms   p(90)=215.23µs p(95)=224.14µs
     iterations.....................: 149193  4972.914031/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Dec 10, 2024

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 238662      ✗ 0     
     data_received..................: 24 MB   800 kB/s
     data_sent......................: 9.5 MB  318 kB/s
     http_req_blocked...............: avg=1.35µs   min=882ns    med=1.17µs   max=199.78µs p(90)=1.86µs   p(95)=2.02µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=142.31µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=191.19µs min=143.42µs med=179.71µs max=10.56ms  p(90)=205µs    p(95)=213.54µs
       { expected_response:true }...: avg=191.19µs min=143.42µs med=179.71µs max=10.56ms  p(90)=205µs    p(95)=213.54µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 119331
     http_req_receiving.............: avg=24.89µs  min=13.32µs  med=23.48µs  max=5.19ms   p(90)=30.23µs  p(95)=32.43µs 
     http_req_sending...............: avg=6.05µs   min=4.04µs   med=5.28µs   max=477.71µs p(90)=8µs      p(95)=8.44µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=160.25µs min=116.4µs  med=148.22µs max=10.52ms  p(90)=170.78µs p(95)=178.88µs
     http_reqs......................: 119331  3977.561912/s
     iteration_duration.............: avg=247.11µs min=189.62µs med=234.68µs max=10.74ms  p(90)=263.78µs p(95)=274.46µs
     iterations.....................: 119331  3977.561912/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan changed the title fix(node-fetch/URL): parse IPV6 hostnames correctly in URL, and also reflect changes in toString when searchParams modified Several fixes Dec 10, 2024
@ardatan ardatan merged commit 7fb47d8 into master Dec 10, 2024
25 checks passed
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 this pull request may close these issues.

ipv6 hostname inconsistency with parsing & pattern matching
1 participant