Raycast passes through colliders

Hello. I work with Unity 2021.3.37f1.

I was creating a laser using Raycast when I met with a problem:
My ray is passing through colliders sometimes and I don’t know what to do.

I uploaded the video with the issue on Youtube:

And here is the script of the laser:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Laser : MonoBehaviour
{
    LineRenderer lineRenderer;

    LaserCatcher laserCatcher;

    Vector3 firstPosition = new Vector3(0, 0.5f, 0);
    Vector3 secondPosition;

    RaycastHit hit;

    void Start()
    {
        lineRenderer = GetComponent<LineRenderer>();
    }

    void Update()
    {
        if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))
        {
            lineRenderer.enabled = true;
            
            var secondPositionZ = transform.InverseTransformPoint(hit.point).z;
            if(secondPositionZ < 0) secondPositionZ = -secondPositionZ;
            
            secondPosition = new Vector3(0, 0.5f, secondPositionZ);

            lineRenderer.SetPosition(0, firstPosition);
            lineRenderer.SetPosition(1, secondPosition);

            print(hit.collider);

            LaserCatcher lc = hit.collider.GetComponent<LaserCatcher>();
            if(lc != null) 
            {
                laserCatcher = lc;

                laserCatcher.catchedLaser = true;
            }
            else
            {
                if(laserCatcher != null) laserCatcher.catchedLaser = false;
                laserCatcher = null;
            }
            
        }
        else
        {
            lineRenderer.enabled = false;
        }
    }
}