简体   繁体   English

将 SIGKILL 发送到 `git status` 是否安全?

[英]Is it safe to send a SIGKILL to `git status`?

I want to stop Git if it takes too long to run git status , but Git seems to be ignoring SIGTERMs: Why does timeout not interrupt `git status` when it takes too long?如果运行git status花费的时间太长,我想停止 Git,但是 Git 似乎忽略了 SIGTERMs:为什么超时不中断 `git status` 花费的时间太长?

So it seems that one way to get around this is to use SIGKILL, but that you may hit a bug and corrupt your repository if you send a SIGKILL: https://stackoverflow.com/a/63212737/11588505因此,似乎解决此问题的一种方法是使用 SIGKILL,但是如果您发送 SIGKILL,您可能会遇到错误并损坏您的存储库: https://stackoverflow.com/a/63212737/11588505

git status is purely a query, though, so shouldn't it be perfectly safe to send a SIGKILL?但是, git status纯粹是一个查询,所以发送 SIGKILL 不是绝对安全的吗?

Since SIGKILL cannot be caught and immediately terminates Git, this may leave behind various oddities or problems.由于无法捕获SIGKILL并立即终止 Git,这可能会留下各种奇怪或问题。

Git is designed to be reasonably resilient: for instance, instead of just writing out its index, it writes an updated index to a file named .git/index.lock , and then uses what's meant to be an atomic OS-level process to replace the old .git/index file with the new contents in .git/index.lock while calling the new file .git/index . Git 被设计为具有相当的弹性:例如,它不只是写出它的索引,而是将一个更新的索引写入一个名为.git/index.lock的文件,然后使用一个原子操作系统级进程来替换在调用新文件.git/index时,旧的.git/index文件在.git/index.lock中包含新内容。 This atomic operation is a rename system call: Git depends on the OS to implement it as an atomic operation, that either completely happens, or never starts.此原子操作是rename系统调用:Git 取决于操作系统将其实现为原子操作,要么完全发生,要么永远不会开始。

Similar schemes are used to update references and other files, including loose objects and pack files.类似的方案用于更新引用和其他文件,包括松散对象和包文件。 Not every file system on every OS obeys these rules, and if the OS itself crashes, you can get into various troublesome cases, but on the whole this works pretty well.并非每个操作系统上的每个文件系统都遵守这些规则,如果操作系统本身崩溃,您可能会遇到各种麻烦的情况,但总的来说它工作得很好。

What happens if Git is killed, with the un-catch-able SIGKILL , during one of these critical sections is that the lock file remains left behind.如果 Git 在这些关键部分之一期间被无法捕获的SIGKILL杀死,会发生什么情况是锁定文件仍然存在。 A future Git invocation stops and tells you that there is a lock file and it cannot proceed.未来的 Git 调用停止并告诉您有一个锁定文件,它无法继续。 It then becomes your job to inspect the system as a whole, determine whether this is a stale lock, and hence whether it can be removed.然后你的工作就是检查整个系统,确定这是否是一个过时的锁,并因此确定它是否可以被删除。 If so, removing the stale lock and retrying the operation should recover.如果是这样,删除陈旧的锁并重试该操作应该可以恢复。

When the OS itself crashes, Git may lose files that Git cannot operate without.当操作系统本身崩溃时,Git 可能会丢失 Git 无法运行的文件。 Your best bet for this kind of problem is to have another repository somewhere else, preferably physically distant so that a common event (eg, building catches fire and all the computers within it burn up or are ruined by fire suppression) does not damage the other Git repository.解决此类问题的最佳选择是在其他地方建立另一个存储库,最好在物理距离较远的地方,这样一个常见事件(例如,建筑物着火并且其中的所有计算机都被烧毁或被灭火破坏)不会损坏另一个存储库Git 存储库。 For less extreme cases, sometimes the repository is repairable in-place.对于不太极端的情况,有时存储库可以就地修复。

One of the most common failures is for the OS to completely delete the file named .git/HEAD , and with this file gone, Git no longer believes that the repository is a repository.最常见的故障之一是操作系统完全删除名为.git/HEAD的文件,随着这个文件的消失,Git 不再认为存储库是存储库。 Re-create the file (eg, echo ref: refs/heads/master >.git/HEAD ) and the repository is back.重新创建文件(例如, echo ref: refs/heads/master >.git/HEAD ),存储库又回来了。 If your system obeys the POSIX file atomicity rules, this particular case cannot happen even for SIGKILL .如果您的系统遵守 POSIX 文件原子性规则,则即使对于SIGKILL也不会发生这种特殊情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM