fix(ci): ETIMEDOUT for ipv4 & ENETUNREACH for ipv6 when fetching fonts from @unocss/preset-web-fonts (#268)

Co-authored-by: XYenon <20698483+xyenon@users.noreply.github.com>
This commit is contained in:
Neko
2025-07-14 20:38:44 +08:00
committed by GitHub
co-authored by XYenon
parent b21f4b4da7
commit aca3c589f6
+28
View File
@@ -1,5 +1,7 @@
import type { Preset, PresetOrFactoryAwaitable } from 'unocss'
import { setDefaultAutoSelectFamilyAttemptTimeout } from 'node:net'
import { createExternalPackageIconLoader } from '@iconify/utils/lib/loader/external-pkg'
import { presetChromatic } from '@proj-airi/unocss-preset-chromatic'
import { colorToString } from '@unocss/preset-mini/utils'
@@ -8,6 +10,32 @@ import { defineConfig, mergeConfigs, presetAttributify, presetIcons, presetTypog
import { presetScrollbar } from 'unocss-preset-scrollbar'
import { parseColor } from 'unocss/preset-mini'
// On Netlify, building will result in when fetching metadata and fonts from @unocss/preset-web-fonts plugin:
//
// [cause]: AggregateError [ETIMEDOUT]:
// at internalConnectMultiple (node:net:1134:18)
// code: 'ETIMEDOUT',
// [errors]: [
// Error: connect ETIMEDOUT 146.75.77.229:443 ...
// Error: connect ENETUNREACH 2a04:4e42:83::485:443 - Local (:::0) ...
// ]
//
// This is same for either Google Fonts or Fontsource as provider. But GitHub Actions and local development works fine.
// My assumption is that the default timeout for auto-selecting family is too short (250ms)[^1] for the implementation
// of the Happy Eyeballs algorithm in Node.js, which is used by the `net` module to connect to the server, workflows
// illustrates like this:
//
// lookupAndConnect > autoSelectFamilyAttemptTimeout > lookupAndConnectMultiple > internalConnectMultiple > defaultTriggerAsyncIdScope
//
// Such mechanism will be used when the `net` module attempts to connect to a server using both IPv4 and IPv6 addresses,
// which is the case for Netlify builder.
//
// In order to fix this issue, we can increase the timeout to 1000ms (1 second) so that the algorithm has more time to
// attempt to connect to the server before timing out.
//
// [^1]: https://github.com/nodejs/node/pull/44731/files#diff-d76469e9e7f555294a7a5488c5c8fc4ef8ce5aea448cc26a1322d1ab693e09caR921
setDefaultAutoSelectFamilyAttemptTimeout(1000)
export function presetStoryMockHover(): PresetOrFactoryAwaitable {
return {
name: 'story-mock-hover',