diff --git a/pyopencl/cache.py b/pyopencl/cache.py
index 59f41349101aaddc2037906e79120658b1521752..7719c3a8da3d5f9c855384350f45b41a303d0f34 100644
--- a/pyopencl/cache.py
+++ b/pyopencl/cache.py
@@ -150,6 +150,9 @@ def get_dependencies(src, include_path):
                     finally:
                         src_file.close()
 
+                    # prevent infinite recursion if some header file appears to include itself
+                    result[included_file_name] = None
+
                     checksum = new_hash()
                     update_checksum(checksum, included_src)
                     _inner(included_src)