aiida-core icon indicating copy to clipboard operation
aiida-core copied to clipboard

`Transport` & `pytest`: garbage cannot be removed `[Errno 39]`

Open khsrali opened this issue 10 months ago • 24 comments

To reproduce

When running pytest test_all_plugins.py -s, despite all tests passing successful, a long tail of warning messages is printed:

..
  warnings.warn(
/home/**/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-khosra_a/garbage-82a5592f-5337-4d9c-934e-7a6ace59c9a7/popen-gw0/remote7
<class 'OSError'>: [Errno 39] Directory not empty: 'remote7'
  warnings.warn(
/home/**/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-khosra_a/garbage-82a5592f-5337-4d9c-934e-7a6ace59c9a7/popen-gw0
<class 'OSError'>: [Errno 39] Directory not empty: 'popen-gw0'
  warnings.warn(
/home/**/lib/python3.12/site-packages/_pytest/pathlib.py:95: PytestWarning: (rm_rf) error removing /tmp/pytest-of-khosra_a/garbage-82a5592f-5337-4d9c-934e-7a6ace59c9a7/popen-gw4/remote8
<class 'OSError'>: [Errno 39] Directory not empty: 'remote8'
..

that pytest cannot clean the garbage.

To be investigated. Also pinging @unkcpz

khsrali avatar Feb 10 '25 12:02 khsrali

Hey if Its not deleting Why not delete it Manually and then runs the Test

FARDEEN-785 avatar Feb 12 '25 02:02 FARDEEN-785

Because we don't want to do it manually, and because it should not happen. :-)

khsrali avatar Feb 12 '25 09:02 khsrali

Because we don't want to do it manually, and because it should not happen. :-)

Can't we can use Force method to delete

FARDEEN-785 avatar Feb 12 '25 14:02 FARDEEN-785

The issue me relate to https://github.com/pytest-dev/pytest/issues/12381, which may or may not resolved from our side. If someone what to pick this issue, would be nice to have a deep understanding on problem of data racing introduced by pytest-xdist and how to avoid it nicely.

unkcpz avatar Feb 13 '25 17:02 unkcpz

Well I am new to this and don’t have deep understanding but still I will try to resolve this issue

FARDEEN-785 avatar Feb 13 '25 17:02 FARDEEN-785

hello @khsrali , is this issue still open? If yes, can I proceed with this ?

crs7617 avatar Feb 25 '25 17:02 crs7617

Hi @crs7617,

I think also @ayushjariyal showed some interest working on this. I don't know if he's still working on it or not.

khsrali avatar Feb 26 '25 08:02 khsrali

@khsrali I am working on it. Right now, my semester exams are going on, so I am unable to give my full time to this. However, I am trying my best.

ayushjariyal avatar Feb 26 '25 08:02 ayushjariyal

It's all good, no hurry! take your time.

khsrali avatar Feb 26 '25 08:02 khsrali

@khsrali Thanks for the update! if there's anything I can help with, feel free to let me know.

crs7617 avatar Feb 26 '25 08:02 crs7617

@khsrali, I noticed that @ayushjariyal is currently working on issue #6728. I just wanted to clarify if issue #6751 is separate from that, or if they are related. If they are distinct, I’d be happy to proceed with #6751. Let me know what you think!

crs7617 avatar Feb 26 '25 08:02 crs7617

They are independent issues. I don't know. Maybe @ayushjariyal should answer, if he's also working on that. For me, either way is ok.

khsrali avatar Feb 26 '25 09:02 khsrali

alright, thanks for the clarification !

crs7617 avatar Feb 26 '25 09:02 crs7617

@crs7617 in case you also have a solution for https://github.com/aiidateam/aiida-core/issues/6728, please feel free to provide it. I think solving that issue is kinda high priority.

khsrali avatar Feb 27 '25 11:02 khsrali

@crs7617 in case you also have a solution for #6728, please feel free to provide it. I think solving that issue is kinda high priority.

sure , I had an idea about #6751 , I am just going through #6728 rn

crs7617 avatar Feb 27 '25 12:02 crs7617

Hi @crs7617 I had a solution for https://github.com/aiidateam/aiida-core/issues/6728 in mind, so I put it on https://github.com/aiidateam/aiida-core/pull/6776 you can give us your opinion on that solution!

if you already have a solution of this current issue https://github.com/aiidateam/aiida-core/issues/6751, please don't hesitate to provide it. Cheers!

khsrali avatar Feb 27 '25 13:02 khsrali

Hey @khsrali ,

I investigated the issue thoroughly and found that Aiida's codebase does not have any errors related to garbage file management. The problem lies in Pyenv, where some directories are not being deleted properly because they are still not empty when Pytest attempts to remove them in pathlib.py.

Image

To resolve this, I updated the function to forcefully delete those files,

Image

and after the update, the warnings no longer appeared.

Image

Could you please let me know if I missed anything or made any mistakes?

ayushjariyal avatar Mar 02 '25 19:03 ayushjariyal

Hi @ayushjariyal, Thanks a lot for looking into this. May you please direct me where this function, rm_rf is defined? is this something you wrote? or is it part of pyenv? if that's the case, maybe it makes more sense to fix this in the upstream

khsrali avatar Mar 03 '25 08:03 khsrali

Hi @khsrali , You're welcome! The rm_rf function is part of pyenv and can be found at:

/home/user/.pyenv/versions/3.9.20/lib/python3.9/site-packages/_pytest/pathlib.py

Since it belongs to pyenv, it might make sense to fix this upstream, but I'm not quite sure how to go about it.

ayushjariyal avatar Mar 03 '25 10:03 ayushjariyal

You can find it on github here: https://github.com/pytest-dev/pytest/blob/main/src/_pytest/pathlib.py#L162

ayushjariyal avatar Mar 03 '25 10:03 ayushjariyal

Alright!

Thanks @ayushjariyal ! in that case, I think we should open an issue and ask pytest. Can you please take care of that? Explaining the issue clearly and your proposed solution. Please also include your setup info. Both python version and pytest version.

Once the issue is opened, please also put a link here, so we can track to see what happens.

Cheers!

khsrali avatar Mar 03 '25 10:03 khsrali

Sure! I'll open and issue with pytest.

ayushjariyal avatar Mar 03 '25 12:03 ayushjariyal

I opened an issue regarding this problem. You can find it here: https://github.com/pytest-dev/pytest/issues/13269

ayushjariyal avatar Mar 10 '25 04:03 ayushjariyal

@adityagh006, chatgpt? 🙃

It's ok to use chatgpt for coding and development. However, the proper use of chatgpt is to actually try and develop and you mange to refine and make it work. The plain suggestions, as you put here, we could also get ourselves 💁

khsrali avatar Mar 11 '25 08:03 khsrali