Open jeroenlaylo opened 1 month ago
The tmp directory will be used in many operations. Maybe we need a TMP_DIR configuration rather than use system's. I wouldn't say this is a bug but a proposal or enhancement.
I personally don't recall this being the case in the past though (I have also been facing this issues on 1.22.0+dev-686-gee242a08e9
), do we know when and what changed this?
The tmp directory will be used in many operations. Maybe we need a TMP_DIR configuration rather than use system's. I wouldn't say this is a bug but a proposal or enhancement.
IIRC, this hasn't always been the case. I have been contacted by some users that the Gitea instance was sluggish, upon investigation it turned out that this was due to a full /tmp
partition. A rough estimation: it is likely a change introduced in 1.20.x
, 1.21.xor
1.22.x`.
The TMP_DIR
setting/variable would be an ideal addition, yeah.
I personally don't recall this being the case in the past though (I have also been facing this issues on
1.22.0+dev-686-gee242a08e9
), do we know when and what changed this?
Thank you kindly for your feedback. This takes some of the doubts away that I was having (whether it wasn't just PEBCAK). Do you experience this on OpenBSD - or on a different OS?
IIRC, this hasn't always been the case. I have been contacted by some users that the Gitea instance was sluggish, upon investigation it turned out that this was due to a full /tmp partition. A rough estimation: it is likely a change introduced in 1.20.x, 1.21.xor1.22.x`.
yeah, I think I would have noticed, been using Gitea for some time now, too.
The TMP_DIR setting/variable would be an ideal addition, yeah.
I concur, making this configurable would be preferable.
I can imagine a decision to speed up the indexer was made at some point, which moved its files to /tmp, since it's mostly ramfs these days.
Thank you kindly for your feedback. This takes some of the doubts away that I was having (whether it wasn't just PEBCAK). Do you experience this on OpenBSD - or on a different OS?
and I am equally glad you opened this issue, because I was having these doubts myself, since I don't get to spend as much time tuning my instance as I used to.
I haven't mentioned this, sorry; I have been running Gitea on Arch (a Linux distro), but I'd expect this behaviour to be largely similar among OSs at least in that it uses system's temp folder.
TMP_DIR
is necessary I think.
I have met a similar problem when install Python packages by pip.
By default, pip also using /tmp as temp directory, if it is too small, you may get error during the installation.
But pip has some env options like TMP_DIR
, so it is easy to fix this issue: just use another directory.
From diving somewhat further, it seems the problem is that cancel()
is never called on erroring out - causing leftover temporary files to not be cleaned. Here is a quick patch:
Index: modules/git/repo_index.go
--- modules/git/repo_index.go.orig
+++ modules/git/repo_index.go
@@ -51,7 +51,7 @@ func (repo *Repository) readTreeToIndex(id ObjectID, i
// ReadTreeToTemporaryIndex reads a treeish to a temporary index file
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename, tmpDir string, cancel context.CancelFunc, err error) {
- tmpDir, err = os.MkdirTemp("", "index")
+ tmpDir, err = os.MkdirTemp("${LOCALSTATEDIR}/gitea/tmp", "index")
if err != nil {
return filename, tmpDir, cancel, err
}
@@ -63,9 +63,16 @@ func (repo *Repository) ReadTreeToTemporaryIndex(treei
log.Error("failed to remove tmp index file: %v", err)
}
}
+
+ // Defer the cancel function to ensure cleanup in case of an error
+ defer func() {
+ if err != nil {
+ cancel()
+ }
+ }()
+
err = repo.ReadTreeToIndex(treeish, filename)
if err != nil {
- defer cancel()
return "", "", func() {}, err
}
return filename, tmpDir, cancel, err
This was only tested on OpenBSD and fixed the behaviour we were seeing. Setting the tmpDir
to a custom path is something that fits our scenario better.
Description
We are running Gitea (
1.22.1
) on OpenBSD (7.5-current
onamd64
). For some reason, Gitea keeps writing index files to/tmp
, despite having configured different paths in the Gitea config. Since this partition is 3GB, it fills up rather quickly.What causes this behaviour? Is there a configuration option that we are missing? If it possible to have Gitea use a custom path for these temporary indexes?
Our config:
Gitea Version
1.22.1
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
We are using the OpenBSD package
Database
PostgreSQL