疑难杂症

Mac硬盘清理

月盾

256G 的 MacBook Pro 用了2年了,最近发现磁盘空间越来越小,每次重启后还能剩余 20G 的空间,用一天后就开始硬盘余额告急,能清理的都清理了,还是不够用。实在找不到能够清理的内容了。

截屏2023-12-30%2014.08.25.png

但是“其他”选项占用了大部分磁盘空间,可以这该清理什么内容呢?

可以尝试在命令行执行以下命令:

查看具体文件夹信息

du -sh <folder>

找到大文件,可以尝试删除。

rm -rf <file>

比如查看~/Library/Caches目录

$ du -h -d 1 | sort -h

会输出当前目录下所有子文件夹的大小,根据实际情况来清理。

截屏2023-12-30%2014.09.08.png

一顿深度清理后,磁盘空间腾出40G来,总算能再撑一段时间了。

next.js项目使用pm2 reload出现502

月盾

为了使next.js项目能够不宕机,使用了pm2守护进程,既能保证node出现异常情况能够自动重启,也能保证服务器整机重启时自动恢复服务。多年使用下来的确能够良好运行,不过最近却出现了与原本期望不符的情况。

在已经启动next.js项目的情况下,如果需要重启,我使用了pm2 reload appname,实际上没有完美的零停机重启,反而是直接出现服务不可用,访问网站就502,并且一直无法恢复。在查阅pm2 issue后发现确实有这样的bug。

无奈,只能使用pm2 restart来重启应用。

Centos Appstream Error

月盾
[root@hecs-221218 network-scripts]# yum install rsync
CentOS-8 - AppStream                                                 3.4 kB/s | 394  B     00:00
Errors during downloading metadata for repository 'AppStream':
  - Status code: 404 for https://repo.huaweicloud.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 61.172.228.200)
Error: Failed to download metadata for repo 'AppStream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

解决办法:

修改/etc/yum.repos.d/CentOS-AppStream.repo中的baseurlbaseurl=https://mirrors.aliyun.com/centos/8-stream/AppStream/x86_64/os/

Ld Warning Object File Was Built for Newer MacOS Version Than Being Linked

月盾

go run和go build会报出一连串下面这样的警告信息,虽然不影响程序运行,但是看着难看。

# command-line-arguments
ld: warning: object file (/var/folders/9p/2x3ls9kn7qb59hf9l9mtfs8s6rbmfg/T/go-link-3994413096/000000.o) was built for newer macOS version (12.0) than being linked (11.0)

解决方法:CGO_CFLAGS=-mmacosx-version-min=10.12 go run main.go,运行前加CGO_CFLAGS=-mmacosx-version-min=10.12参数可以解决。

vscode中可以通过配置launch.json文件实现:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Package",
      "type": "go",
      "request": "launch",
      "env": {
        "CGO_CFLAGS":"-mmacosx-version-min=10.12"
      },
      "program": "${fileDirname}",
      "args": [],
      "cwd": "${fileDirname}"
    }
  ]
}

或者从文件中读取环境变量:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Package",
      "type": "go",
      "request": "launch",
      "envFile": "${workspaceFolder}/.env",
      "program": "${fileDirname}",
      "args": [],
      "cwd": "${fileDirname}"
    }
  ]
}

如果是在vscode中执行测试代码,则需要设置settings.json文件:

puppeteer TypeError: text is not iterable

月盾
(node:9828) UnhandledPromiseRejectionWarning: TypeError: text is not iterable
    at Keyboard.type (D:\workspace\auto-ui\node_modules\puppeteer-core\lib\Input.js:160:24)
    at Keyboard.<anonymous> (D:\workspace\auto-ui\node_modules\puppeteer-core\lib\helper.js:112:23)
    at openBrowser (D:\workspace\auto-ui\test-email\index.js:106:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:9828) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:9828) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

错误原因:input输入框的type=text,但是输入的可能是其他类型,比如输入数字就会报错。

win10家庭版组策略

月盾

win10家庭版本身不支持组策略,但还是有办法让其支持。 复制下面内容到文本文件:

@echo off
pushd "%~dp0"
dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt
dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt
for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"C:\Windows\servicing\Packages\%%i"
pause

后缀名保存为cmd,以管理员身份执行:

然后WIN+R中执行gpedit.msc即可打开组策略。

如此可以关闭占用CPU过高的Windows Defender。

github提交不记录Contributions

月盾

github上提交了很多commit但是没有Contributions绿色方块,原因是提交的email和github不匹配,使用git log查看记录中使用的邮箱是否是github的邮箱,如果不是也不需要做什么修改,只需要在github上添加对应的邮箱地址即可。

右上角头像-settings-emails-Add email address

验证邮箱后就会立马重新统计

请求发送到Nodejs服务器以后响应非常慢

月盾

在项目中遇到过这种情况:请求发送后迟迟没有响应,但也并没有报错,在代码中一步步调试都没有发现问题,明明已经走到最后返回数据一步了客户端却没有返回。原因是在中间件中使用了redis或memcache缓存,然后连接缓存服务失败,然后就会一直等待,直到连接缓存超时才会继续执行后续操作。

BAE上连接mongodb每隔十多小时就不能连接的问题(二)

月盾

前段时间写了《BAE上连接mongodb每隔十多小时就不能连接的问题(一)》之后暂时的解决了连不上的问题,每隔十小时重启一次,但是这个方法却没有彻底解决问题,偶尔还会出现三四小时就连不上,实在搞不懂问题到底出在哪,到底是bae的mongodb的问题还是mongoose中间件的问题,现象是有做open操作,但是却没有open事件发出,那么我想是不是mongoose存在bug,翻看了源码也没看出来个所以然,不过大概是觉得要重新打开需要保证连接已经关闭的,那么干脆在监听到error事件时就将状态直接改为disconnected,反正是要调用db.close()方法进行关闭连接的,可能close()方法不好使,没有完全关闭,如果我手动将状态设为disconnected,close方法中也会判断是否是这个状态,如果是就直接返回,省的多走其他步骤了。不过这样一来就不会有close事件发出了,根据我所写代码的逻辑,那就不会调用open()方法了,但实际情况确实程序可以正常运行,说明已经重连上了,原来在代码中添加了这个属性:

Js代码 :

var opts = { 
db: { 
  native_parser: true  
}, 
server: { 
  poolSize:4, 
  auto_reconnect: true  
}, 
user: username, 
  pass: password 
};

上面的红色字体,只能说是可能这个参数起作用了。

不过由此看来,auto_reconect这个参数要起作用必须是在连接断开的情况下,说明close()方法有时候并没有完全断开连接。