Debug Notes to Self

  • use forever to run node server, pls check which user
  • Apache ProxyPass, did you even open the port on AWS?
  • Order directive is only under <Directory>
  • You almost always need export NODE_ENV=production
  • Chrome caches EVERYTHING without letting you know
  • Pls, if you are putting virtualhost files into sites-available, check whether you have symlink in sites-enabled
  • Apache config file must end with .conf, it seems
  • In new versions of apache2, 'Satisfy Any' and 'Require all granted' are needed
  • It seems by default it's specified somewhere that Apache listen to 80. Don't put
  • Listen 80 at the front of your virtualhost file. Listening to other ports is fine
  • When random newly added files cannot be read/found, do vagrant reload
  • Wondering why can't access a certain port? Is it forwarded from host to guest?
  • When you have your <?php tag wrong, it reports funny syntax errors
  • Remote access to MySQL, you have quite some to do and check:
    • Open port
    • my.cnf comment out bind-addr and skip-network
    • Grant privileges
    • CORRECT username and pw
    • Restart server
  • Know the thing you paste! "Grant ... Identified by" is for specifying password
  • Finally. This thing dragged me for more than 5 hours. See cant-connect-to-mysql-from-php-but-is-able-to-connect-from-remote-machine. So the conclusion is, % sign would not work. Maybe MySQL doesn't allow connect from everywhere using the % sign. Use localhost.
  • MPVolumeView does not appear on simulaor, but only on iPad. Watch out for elements like that.
  • The sequence at which you do things matters. So if in Step 1 you changed an object via its reference, don't expect it to be intact in Step 2.
  • Sometimes you are just too happy that you pass the wrong parameters (yet of same type). Be ware.
  • Be careful whether the coordinates are relative to the view or screen
  • It's important to do explicit type casting carefully. int and NSUInteger can be very different, especially with 0;
  • Error messages, even the unreasonable ones such as Objective-C linker error code, are meant to be read. Read it and a lot of problems become crystal clear and trivia to solve
  • The sequence at which one does fork() and doSth() matters a lot!
  • When bug is not at where you are looking, you can't find it. Check whether control even passes the statements?
  • When you can't update a package using npm, you might be using (running) it
  • When you have something like: <img alt="" /> <img alt="" /> You will see a small gap in between. That's because it's displaying the newline character.
  • jquery has .height(), .innerHeight(), .outerHeight()
  • Just can't get encode/decode right: the Unicode that we can see and understand encodes to Bytes that is binary and non-readable. The non-readable Bytes be decoded into Unicode
  • When there is a space in file name, you will be able to open that resource in new tab from chrome console. But it can't be properly loaded as a background-image with invalid property value error
  • Java applet no longer works on webpages as of recent versions of chrome
  • When need to do "match X (e.g. character class), but can't be exactly YY or YYY", use non consuming regex group. E.g. need to match /someFile/../, but not /./../ or /../../: /\/(?!\.\.\/)([^/]+)\/\.\.\//
  • What's still not working with Bash on Ubuntu on Windows?
    • phantomjs-prebuilt. It doesn't know whether you are ubuntu or windows. pulls the wrong binary - solution: install phantomjs globally (sigh...)
    • Old ver of ubuntu (14.04)
    • Arrow keys not working, ComEmu + UBW + vim
    • yarn pkg doesn't work because no network interface
  • Ign xxx.source.list is normal output from ubuntu - simply means "no change in this source list"
  • windows show listening ports netstat -a -b -o
  • When you just can't figure out why port can't be connected or why it's being listened - remember you are in a big mist of subsystems. Do you have it in one of your vbox, and port is forwarded to host? Do you have it running in BUW?
  • It's a redux devtools but that if a dispatch is called in dom event handler, it's not caught by devtools. But it will be caught by redux store
  • It's important and tricky to create minimal repro for bug. Most of the times you would think the problem is in your code - not always! Sometimes it IS in the library or tool that you are using. Either way, create what works and what doesn't, approach each other from both sides, as appropriate
  • For jQuery posting JSON (application/json), you must give serialized JSON string in data
  • Email regex:
    /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
  • Silly bug. I change js file and restart node process, and then grep log for keyword A (cache_purge). I wonder why my logging of xxxx doesn't show up. Lesson: use grep -C 3
  • SSH never works for me. Check your username, check keys, use -vvv to debug
  • What is tilda in bash? It's available only in terminal, not in .bashrc (because you don't have a HOME at that time?). Use $HOME in .bashrc etc
  • vue cmd not found. 一开始认定肯定不在path, 后来看pkg自己都没有bin? 原来装错了, cli-global-service是专给serve用的plugin, 但是在这之前先装@vue/cli才行

  • 然后因为一些神秘的原因找不到vue.esm.js, 直接给一个绝对路径反而就import成功了, good job webpack (no pun intended)

  • getMonth 从0开始数

  • fs.writeFileSync 不认识 ~ home directory

  • ssh-agent要想跑多个subprocess cmd要这样 ssh-agent bash -c 'ssh-add /home/ubuntu/go/src/github.com/dexDev/dexPanel/web/editText/temp; cd ${DFE3_PATH}; git push origin master'

  • Your current version of Yarn is out of date “npm upgrade –global yarn” should be “npm install –global yarn” #3042 https://github.com/yarnpkg/yarn/issues/3042

  • 可以格盘么?意思是可以整盘摧毁么?mkfs -f /dev/diskAccessPoint 或者 dd if=/dev/zero of=/dev/diskAccessPoint bs=1M count=1000 find /forRemovePath/* -exec rm -f {} \;

  • git rev-list --all --pretty "%H %an %at"

  • All these workarounds didn’t work for me: https://github.com/alanz/vscode-hie-server/issues/89 In the end I must move the one in 8.4.4?? But moving the .o in 8.4.3 has effect - it crashes

  • Was filing a bug report to jest / webpack because I think it messed up node require logic in their Runtime.requireModuleOrMock. Turned out I was wrong. It gave wrong results because alias was defined in webpack conf, so webpack doing the wrong resolution of modules

  • 一开始是以为React component, purecomponent没有re-render, 导致还是旧的数据. 后来仔细看了一下做的都是对的, 有re-render. 那么怎么回事呢? 原来在selectedRows 里面, 我放的不是idx (或hash) 而是整个data obj. 所以不跟着更新. 是个subtle bug, 留pointer最好, 或者留key

  • 踢到Spring的铁板. 一开始以为所有properties file和yaml file全都100%兼容, 后来发现在阴暗的角落里竟然: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-yaml-shortcomings @PropertySource只能用properties

  • Vault, 原来api_addr和vault_addr不是一回事. vault_addr不能在config文件里写, 但是却有个默认值, 是127.0.0.1. 而其他几个addr就设成 (也应该) 是127.0.0.1. 导致快疯了. 最后还是CLI传, 或者envvar

  • Python logging, setLevel放在handler这一层, 结果还是总用default last resort (也就是WARN). 幸好发现得早, 没有乱找. 最后发现是handler和logger都需要setLevel, logger那一层先筛

  • “极端情况下ETH的bug”, 是说前一个交易广播出去但是在pool里没有进块. 这时钱还在. 然后又发后一个交易. 然后前一个交易成功进块了. 最后钱不够后一个交易了, 后一个交易永远卡死.

  • alphavantage的json api:
    {
      "Realtime Currency Exchange Rate": {
          "1. From_Currency Code": "USD",
          "2. From_Currency Name": "United States Dollar",
          "3. To_Currency Code": "USDT",
          "4. To_Currency Name": "Tether",
          "5. Exchange Rate": "0.99588996",
          "6. Last Refreshed": "2019-10-21 15:12:10",
          "7. Time Zone": "UTC",
          "8. Bid Price": "-",
          "9. Ask Price": "-"
      }
    }
    
  • Why you can’t fake your IP? Because 1. Reply TCP packets will not deliver 2. If you fake an IP that this exit router doesn’t expect, it will drop. Unless you control all exit routers.

  • RocketMQ问题, 先从 no route info开始 (client报的), 然后全线不能发消息. 很慌. 后来分析, MQclient连不上rocketMQ, 然后有的币对还正常, 最后发现rocketMQ的机器正常, 但是有台新机器没有加安全组所以新机器连不上rocketMQ. 还是有几个问题: client连不上我, 为什么我rocketMQ还知道要报错? 后来基本全不行, 是因为碰巧两个API都到了那台27新机器吗? 还是因为机器人所在机器和我的机器都碰巧连同一个API? 后来resequence花了好久 (虽然说出现的错误是经典的卡在submitted状态, 不能取消), 为什么呢? 是不是因为现在的配置还远不如当年的benchmark

  • Maven, goal不生效, 最后发现是因为塞在pluginmanagement里面, 而不是plugins里面. See
      <xs:element name="pluginManagement" minOccurs="0" type="PluginManagement">
          <xs:annotation>
              <xs:documentation source="version">4.0.0</xs:documentation>
              <xs:documentation source="description">
                  Default plugin information to be made available for reference by
                  projects derived from this one. This plugin configuration will not
                  be resolved or bound to the lifecycle unless referenced. Any local
                  configuration for a given plugin will override the plugin&apos;s entire
                  definition here.
              </xs:documentation>
          </xs:annotation>
      </xs:element>
    
  • Gradle缓存问题. 首先版本号重复使用了1.0.0-SNAPSHOT, 在nexus上面会后缀20200000-1 20200000-2 20200000-3这种, 然后用一个类似于softlink. 对于gradle, 本地默认仓库缓存在/root/.gradle/caches/modules-2/, 下面的files然后各个org前缀. 找到这个目录是靠比较占磁盘大小. 我们观察到gradle永远拉老的错的版本. 删掉缓存仍不能解决. 2个怀疑, 要么从nexus拉错误版本, 要么从本地其他隐秘地方cp过来错误版本. 为了验证, 去nexus, 删掉-1 -2 -3… 只留最新版. 删掉files里面缓存. 再build, 终于报错了! 说找不到-8. 所以一直在拉错误的-8版本. 谁指定的呢? 想到/root/.gradle/caches/modules-2/下面还有metadata, 因为小没注意过. 里面是descriptor.bin. cat grep之后发现果然有-8. 删掉就好了. 同时搜索的时候, 也注意到应该没有其他本地仓库缓存了, 不会徒增复杂度. 支持多个registry已经够复杂了
  • AWS上起nexus maven repo. 不像阿里云有现成的, 但是有cloudformation成套配置. 起的时候出了问题, 没有对应AMI. 挖到cloudformation的template里面再一层的template, 看到有一个mapping, 每个区域要用哪个centos AMI. 没有ap-northeast-1! 一开始我心想, 没事啊, 就去东京找个centos. 然后找半天没有名字完全符合的. 找到的都是marketplace上的, 没有直白的AMI ID, 要license使用 (虽然也不付钱). 这样就没法往template里面填嘛. 只好去找非官方的public centos AMI. 然后又想到, 哎我把别的region的AMI复制过来, 不是更完美? 干着干着, 心里觉得有点不对了, 关键点是看到AMI ID的长度, 官方的那些常见的centos的ID很短, 但是这个template里面的很长. 想到了, 这个不是个空白的centos, 而是带着nexus软件塞好的centos! 所以必须复制. 复制不成功, 因为是licensed AMI, 不是我自己的. 有人说, 起一个ec2再打AMI再复制到别的region可以. 也有人说不行, 只要base层里, 有一层是licensed就不行. 最后服了. 把nexus建到一个template有mapping的区域了, us-east-1. 最后还失败了一次, 因为用marketplace里面的AMI, 要同意协议…

  • Spring cloud eureka用Undertow, 主要是undertow使用长链接

  • stripPrefix must be on route level

  • zuul不生效是因为作为client没有fetch registry, 所以serverlist空

  • 今天遇到windows上outlook打不开 (office 365), 排查时发现web office.com 也打不开, 返回的错误信息是中文一看就是定制的. 看office.com dns resolve到127.0.0.1:9000, 翻找杀毒软件, 果然关了之后两个都好了

  • 一个已知问题. eureka + kube注册的时候默认用系统读取的hostname, 是一pod name (带着hash). 所以要preferIpAddr: https://github.com/Netflix/eureka/issues/988 另安装ifconfig是 apt install net-tools

  • git还真是如果ssh的remote, 就用ssh连, https的remote, 就用http连. 学到了: GIT_TRACE=1 git fetch origin

  • Jwt - io.javawebtoken这个库的设计, 说一说. Jwt只是一个里面有header和body的东西. body里面基本上是claims, 也可以是payload. claims才是juice, 里面有所有我关心的field. 所以说我建一个JwtInfo class, 然后里面composition 一个claims, 是对的. 就相当于换了个wrapper

  • @Inherited 不是那样用的 - 不是动态地决定一个annotation是不是inherit, 而是, 在定义一个注解的时候, 决定这个注解是继承还是不继承

  • 一开始在junit5里面不加载不postconstruct一些非该服务的bean (JwtUtil). 后来加了@ContextConfiguration, 各种不对. 最后是加上当前Application, 再加个缺的JwtUtil, 额…

  • 一个小问题. 当用重构新lambda替代旧版本的时候, 直接用了旧lambda的IAM role, 心想全都复制过来了嘛. 结果感觉有点不对, 去cloudwatch查日志还查不到. 最后发现不一样的日志组, 新的lambda往新日志组没权限写. 当然了这个问题和本质没关系, 但是只是缺了日志不好排查. 最后有日志了才看到, 是var改const运行时抛错了. 这个, IDE咋不提醒一下呢.

  • DateUtil遇到以下几个:
    • monthOfYear是0开始, dayOfMonth是1开始. 如果是3号0点, 减三天可就到上个月了
    • 但是分钟小时等都不一样. 日期是直接1号开始, 时间有0点0分, 所以4点就应该减4小时
    • Initializer里面我放了设定timezone UTC的代码, 但是, 是在DateUtil类. 只有第一次用到DateUtil加载类的时候才会跑static initializer, 所以如果 new DateTime() 就不会生效. 最好的方法可能是依赖塞到base, 用implementation, 不要api, 不暴露, 别人不许用
  • Spring找不到bean: Could not find bean of type XXX. 正常思路肯定是看componentScan, basePackage, 按理说在external jar里面的component也是不会有问题的. 为什么呢? 最终这个SO答案给我了灵感, 不一样之处在于, 我这个注入不了的bean是interface, 是feignclient. Interface不能直接实例化, 谁知道怎么实例化呢? 当然是feign这个库自己. 所以需要 @EnableFeignClients("com.XXX"). 那么为什么迁移出来之前没事呢? 因为这个注解的value, 不给, 默认就是当前类的package. 原本是能找到的

domain如果不写, 有默认值. 如果写了domain, 只能一个value

还有一个点就是, 由于port不一样, 构成了一个CORS req. 所以cookie就是不发. 这是一开始的根本原因. 解决是加上withCredentials (fetch 叫credentials: ‘include’), 两边都加, server叫Allow-credentials-bla

但是, 就算上面能解决我的一开始的问题 (恢复到一开始, 去掉Domain attribute), 还是想问, 我作为A.com去往B.com发请求, 应该是可以带B.com的cookie的吧! 只要配置正确. 试一下

还涉及SameSite:

SameSite attribute
The SameSite attribute lets servers require that a cookie shouldn't be sent with cross-origin requests (where Site is defined by the registrable domain), which provides some protection against cross-site request forgery attacks (CSRF).

It takes three possible values: Strict, Lax, and None. With Strict, the cookie is sent only to the same URL as the one that originated it; Lax is similar, with an exception for when the user navigates to a URL from an external site, such as by following a link; None has no restrictions on cross-site requests.

没问题, 终于全对了 总结一下

  • 首先, B.com的请求set的cookie要带给C.com, 不让
  • 只有我说的这种常见情况, 我作为A.com去往B.com连续发请求
  • 两边都带CORS, 是能general带cookie. 还要在cookie上加None, 代表带这个cookie, 不然就例外了

  • 一个TS的问题, Omit, Diff, Exclude, 几个builtin types. 升级了之后报错, 换用就好了. 用途是做object literal only的type substraction. 类型系统挺复杂的, 还可能turing complete!

  • aws ecr get-login-password问题 还真是地区. 一切都对了, 地区对不上的话, 会给400 Bad Request. 太困惑了吧. aws-cli和docker login, 都需要

  • 第一次发现, 这个fetch spec不允许set-cookie! 所以node-fetch只能取回来一个. 用别的http client

  • umi默认的less setup, 这个less如果只import, 不用, 里面的:global也不生效. 可能是被tree shake了. 如果随便干点没意义的空定义然后引进来, 就生效了

  • 删了easyconnect, 之前在什么VPN用过来着? 他有常驻后台的监控程序. 之后似乎快了不少, everything

  • 神奇的ESM / CJS, 一万年了. 这次遇到的是, 如果加上type module, eslint prettier会不行. 不加上, 我自己写的ts脚本不行. 最后用很特殊的loader支持来做: node –loader ts-node/esm ./server/scripts/compile-archives.ts

  • 一个引用的问题, 一开始以为是引用出了当前packagejson范围, 用softlink hardlink都不行. 最后想试一试吧, 复制过来, 还是不行. 原来是后缀名的问题. 加–experimental-specifier-resolution=node似乎就解决了. 哎好吧人家都写了文档里. 但是原来两个都有, 既要link过来, 也要后缀名, 这么个状态.. 哦好像是.d不行, 没支持. 不是! 最后好像是发现, .d.ts文件, 专用于type interface, 不要export value. 所以我class扔进去不对的. 要么改名

  • 不敢信: TypeScript will ignore files with duplicate filenames in the same folder (for example, src/file.ts and src/file.js). TypeScript purposely ignore all but one of the files, only keeping the one file with the highest priority extension (the extension priority order (from highest to lowest) is .ts, .tsx, .d.ts, .js, .jsx). For more info see #955. https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration https://github.com/typescript-eslint/typescript-eslint/issues/955

  • Selenium, Chrome Driver: I had similar error. But versions were matching: I was using Chrome 65 with driver version 2.38.

I spent long time, trying to understand the issue. At the end, found that it was caused by empty /etc/hosts file. Apparently Chrome communicates via localhost, and if such entry missing in /etc/hosts - it will crash.

So, make sure, it has entry like this:

127.0.0.1 localhost

  • 用spring cache, 很好生效了. 但是不是存进redis, redis里没有key? 查了半天, 想还能存进哪个redis呢, 存了就删了? debugger断到cache里面, 看到创建了concurrentmapcache. 好了, 知道是确实不放. 看了半天, 最后生疑, RedisCache怎么没有? 没有这个类. 仔细看了一遍, 结果没有spring-boot-starter-data-redis这个jar. 但是, build.gradle里面是有的? 尝试改错成 implementation 'org.springframework.boot:spring-boot-starter-data-redis11111111', 还是能构建? 这是gradle同步出了问题. 改对回来重新同步, 好了, 显示download对应的jar. 再来就好了. 全自动. 所以前一次可能是没download成功, 以为成功了 (我点叉cancel). 不知道怎么就继续构建了. 然后依赖都是DI, 注入的, 所以没有explicit依赖, 所以还能跑成功, 跑出in-memory cache

ant-design list 渲染

我的妈, 肯定哪里出了问题. lanting的几个list, 一共三四百篇archive, 渲染好几秒. 而且渲染走了两遍, 第二遍才生效. 为什么? 怎么回事?? 不知道. 正在看. 尝试加pagination来看是不是纯渲染耗时. 但是我更怀疑是redux, state, dispatch, 这方面的问题

还真管用, 所以跟渲染应该有点关系. 但是, 还是不知道, 为什么要渲染两次??

后来渲染两次消失了. 分页减少条目数真管用了.

也许是一次没结束强行超时结束了这类原因

  • __dirname有什么问题? 没有问题, 只是ES modules里面用不了

headless chrome on EC2

看看都遇到了哪些问题:

chrome不能用root启动, 因为sandbox dir会有问题 下下来的是zip, 不小心当binary了 chromedriver有了, 也需要chrome binary 创建了www用户, 需要给相关权限

UE4

没有Android binary, 遇到过两次. 这个项目一开始没tick Android, 可能有关. 去掉Engine里面的Android再加回来, 就好了. 不合理

第一次打开VS, 没有code jump. 第二次就好了, 可能也是background task在跑

ssh全都限制permission

ssh进不去, 先passwordauth登进去. 然后

  • authorized keys看了
  • sshd_config看了

吓到, 老子的私钥呢? 不会没了吧? 还好, 我知道我鼓捣了这台服务器最近, 所以大概率还是服务器问题. 试了下private repo还能pull ls -l一下, 看到rwxrwx, 差不多有数了. 对, 果然, authorized_keys, 就像id_rsa, 必须600. 之前之所以改了, 是为了复制给www用户. 一上来还是不行, 600不行, authorized keys要644. 没看sshd日志, 反正通了

一模一样 (?) 的setup, 本地能跑, 远端不能跑

好讨厌这种啊. 没什么意义

node版本也统一了 (算是吧) 所有依赖的lock不可能全统一 os不一样, mac vs linux

发现某一次能跑成功, 太困惑了. 然后发现可能是无用import, 被忽略了, 所以import相关的报错不出来 试比较:

import * as fs from 'fs';
console.log(fs.readdirSync('./'));
import * as fs from 'fs';
console.log('xxx');

最后我发现, 14.10可以, 14.17不行. 苍天啊!

好吧, 既然范围这么小, 我仔细看看吧. 14.12 - 14.13开始不行, 14.13给了非常有用的错误信息:

TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected string to be returned for the “format” from the “loader getFormat” function but got type object.

就是loader的API改了. 那么, ts-node/esm, 是不是也跟着升级了呢? 去看看. 可能是的, 之前用的 9.0.0, 现在10.x.x了

terminal显示问题, 以为是ubuntu / shell / bash / locale的问题

也是一个很深很难搞清楚的东西. 最后, 发现原来是 git config –global core.quotepath off

export NODE_PATH=$(npm root –quiet -g)

global module 没那么容易import, 需要加node path

windows上serve .只能本地访问, 局域网内不行

理所当然以为是防火墙问题, 各种关, 各种实验 (用basic http server), 最后发现是serve优先用了virtualbox host-only network这个interface. 所以IP不对. 都是192 168开头被晃点了

TimeMachine半年不能成功了

失败了2次, 惨痛的教训, 差点砸东西

  • 先是解决了自动锁屏的问题, 自动lock了device, 就没法继续, 晚上挂着也没用: 2022-12-25 09:10:22 Triggered for screen unlock! 2022-12-25 09:10:22 Changed from “deviceIsLocked” to “deviceIsLocked” 2022-12-25 07:00:56 Failed to proactively acquire device lock assertion on lock state change (0). error: Error Domain=NSPOSIXErrorDomain Code=22 “Invalid argument”

  • 然后我也抹了之前唯一一份独苗成功备份, 不要历史包袱了. 格式化还有问题…

  • 最后, 终于定位到 (跟大家的文件不一样, 但是原因类似). 我之前也看到这个, 没多想, 以为是不能assert disk, 仔细看才知道是不能assert file (也有不能assert disk, 就是锁屏问题):

2022-12-25 04:14:36 Failed to acquire device lock assertion for /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/MacBook Pro (5)/2022-12-24-232010/Macintosh HD - Data/Users/testuser/Library/Containers/com.apple.findmy.FindMyWidgetItems/Data/tmp error: Error Domain=NSPOSIXErrorDomain Code=22 “Invalid argument”

终于去看日志, FindMy, 这个sb app, 有问题

为什么老是我遇到bug? 这个就是条件概率了. 程序员 + 瞎折腾, 遇到bug概率就高

Written on December 1, 2013