[Ethereum] Getting: Transaction Error. Exception thrown in contract code in Real

errormetamask

WE Had Create A Dapp Like POWHD, we Already Deployed It And Some Of Transactions Are Already Done well. But After Some Time The issue I'm encountering with my real contract (Dapp) is that trying to send any amount of ETH produces this warning: "Transaction Error. Exception thrown in contract code. Gas limit set dangerously high. Approving every transaction is likely to fail."

Can anyone explain why I am getting this error? I can't understand why an error is producing when someone sends an amount of ETH every time.
“Contract 0x25a06d4e1f804ce62cf11b091180a5c84980d93a”
Warning! Error encountered during contract execution [Out of gas]
For example failed Tra.Hash : https://etherscan.io/tx/0x8da0cc8887aaec2203a0e78f8e56c31482d2c3b5637f2456ec07cc6a8f2e8d1b
Smart contract (TRS)
https://etherscan.io/address/0x25a06d4e1f804ce62cf11b091180a5c84980d93a

Best Answer

The contract has a denial of service vulnerability

For every purchase you have to search linearly if the address is already in contractTokenHolderAddresses_. If you have too many users it will cause an out of gas error. A solution is to use a mapping from address to bool and set to true users who purchase tokens.

function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
    internal
    returns(uint256)
{
    // ------------8<--------------

    bool isFound=false;

    for (uint k=0; k<contractTokenHolderAddresses_.length; k++) {
        if (contractTokenHolderAddresses_[k] ==_customerAddress) {
            isFound=true;
            break;
        }
    }

    if (!isFound) {
        //increment address to keep track of no of users in smartcontract
        contractAddresses_+=1;  
        contractTokenHolderAddresses_.push(_customerAddress);
    }

    // ------------8<--------------