first time error iv encountered in my server,anyone know why?

11/12/2013 05:42 marcbacor6666#1
first time error iv encountered in my server,anyone know why?

[Only registered and activated users can see links. Click Here To Register...]

is it possible that my vps memory is corrupt or faulty?

If i run my server in my pc that problem wont appear, but if i run it in my vps that error will appear.

even if i run any public sources in my current vps that error will appear. It started 2 days ago. Iv been using the vps for almost 3 months with no problem untill november 11.7
11/12/2013 08:14 Y u k i#2
Very nice Multithreading indeed. Good job. I can guarantee you that this wont be an easy fix :3
11/12/2013 08:22 marcbacor6666#3
what do u mean multithreading, multiple making post/thread or multithreading in the source?

iv hosted my game for almost 6 months, and this is the first time that error occur, any idea whats happening? if i run the server in the vps, after few seconds or minutes that error occur, it was not like that past 6 months. but if i run in my pc no error in my server.

at System.Threading._IOCompletionCallback.PerformIOCo mpletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
11/12/2013 12:26 Super Aids#4
Put a try catch in the bitconverter method you have in your source. Put a breakpoint in the catch and then check what values you are parsing. Seems like a problem with the buffer received, perhaps it's trying to access a non-existing offset. That is all I could think of, considering that's the only line mentioned in the thrown exception, but really how do you expect us to help when you give us NO INFORMATION and NOT EVEN ANY CODES.
11/12/2013 15:59 hadeset#5
Quote:
Originally Posted by marcbacor6666 View Post
first time error iv encountered in my server,anyone know why?
Is this an Access Violation exception?
11/13/2013 03:02 marcbacor6666#6
updated

its weird my vps host transferred me to a different ip and that error did not come back. any idea guys? so that in the future if that happens again or happens to other people your ideas can help.
11/13/2013 08:38 Super Aids#7
Thread-safety problem.
11/13/2013 11:39 hadeset#8
Quote:
Originally Posted by Super Aids View Post
Thread-safety problem.
Probably not.
11/13/2013 14:37 lostsolder05#9
Quote:
Originally Posted by Super Aids View Post
Thread-safety problem.
How would that even be a logical conclusion if every source he tried, randomly started doing it after 3 months of no problems? :confused:
11/13/2013 15:49 Y u k i#10
Quote:
Originally Posted by lostsolder05 View Post
How would that even be a logical conclusion if every source he tried, randomly started doing it after 3 months of no problems? :confused:
Probably because most sources are based off the same shit? Mostly Messi v937401 and so on.
11/13/2013 19:34 Spirited#11
I believe someone asked me about this over skype. First, you should strongly consider keeping to one source. Don't "upgrade" whenever a new source comes out on the eastern forum. They're just slowly degrading the quality of the source (and there wasn't too quality to begin with). So, regarding the problem, it most likely is an issue with threading. It wasn't strong to begin with, and with people constantly editing the source without knowing what they're doing, it's just gotten to the point where it cannot function as a server. I'm honestly confused on why you come to this forum to ask these generic questions when you got it from another forum. Why not ask the "programmers" who edited the source?
11/14/2013 05:11 marcbacor6666#12
bitconverter.cs

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C02
{
    public unsafe class BitConverter
    {
        public static ulong ToUInt64(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((ulong*)(Buffer + offset));
            }
        }
        public static uint ToUInt32(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((uint*)(Buffer + offset));
            }
        }
        public static int ToInt32(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((int*)(Buffer + offset));
            }
        }
        public static ulong ReadUlong(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((ulong*)(Buffer + offset));
            }
        }
        public static uint ReadUint(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((uint*)(Buffer + offset));
            }
        }
        public static ushort ReadUshort(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((ushort*)(Buffer + offset));
            }
        }
        public static ushort ToUInt16(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((ushort*)(Buffer + offset));
            }
        }
        public static short ToInt16(byte[] buffer, int offset)
        {
            fixed (byte* Buffer = buffer)
            {
                return *((short*)(Buffer + offset));
            }
        }
    }
}




AssyncSocket.cs

Code:
namespace C02.Network.Sockets
{
    using C02;
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using C02.Interfaces;

    public class AsyncSocket
    {
        private int backlog;
        private int clientbuffersize = 0xffff;
        private WinSocket Connection = new WinSocket();
        private bool enabled;
        public bool GameServer = false;
        private Action<ISocketWrapper> OnClientConnects;
        private Action<ISocketWrapper> OnClientDisconnects;
        private Action<byte[], ISocketWrapper> OnClientReceives;
        private ushort port;

        public event Action<ISocketWrapper> OnClientConnect
        {
            add
            {
                Action<ISocketWrapper> action2;
                Action<ISocketWrapper> onClientConnect = this.OnClientConnects;
                do
                {
                    action2 = onClientConnect;
                    Action<ISocketWrapper> action3 = (Action<ISocketWrapper>)Delegate.Combine(action2, value);
                    onClientConnect = Interlocked.CompareExchange<Action<ISocketWrapper>>(ref this.OnClientConnects, action3, action2);
                }
                while (onClientConnect != action2);
            }
            remove
            {
                Action<ISocketWrapper> action2;
                Action<ISocketWrapper> onClientConnect = this.OnClientConnects;
                do
                {
                    action2 = onClientConnect;
                    Action<ISocketWrapper> action3 = (Action<ISocketWrapper>)Delegate.Remove(action2, value);
                    onClientConnect = Interlocked.CompareExchange<Action<ISocketWrapper>>(ref this.OnClientConnects, action3, action2);
                }
                while (onClientConnect != action2);
            }
        }

        public event Action<ISocketWrapper> OnClientDisconnect
        {
            add
            {
                Action<ISocketWrapper> action2;
                Action<ISocketWrapper> onClientDisconnect = this.OnClientDisconnects;
                do
                {
                    action2 = onClientDisconnect;
                    Action<ISocketWrapper> action3 = (Action<ISocketWrapper>)Delegate.Combine(action2, value);
                    onClientDisconnect = Interlocked.CompareExchange<Action<ISocketWrapper>>(ref this.OnClientDisconnects, action3, action2);
                }
                while (onClientDisconnect != action2);
            }
            remove
            {
                Action<ISocketWrapper> action2;
                Action<ISocketWrapper> onClientDisconnect = this.OnClientDisconnects;
                do
                {
                    action2 = onClientDisconnect;
                    Action<ISocketWrapper> action3 = (Action<ISocketWrapper>)Delegate.Remove(action2, value);
                    onClientDisconnect = Interlocked.CompareExchange<Action<ISocketWrapper>>(ref this.OnClientDisconnects, action3, action2);
                }
                while (onClientDisconnect != action2);
            }
        }

        public event Action<byte[], ISocketWrapper> OnClientReceive
        {
            add
            {
                Action<byte[], ISocketWrapper> action2;
                Action<byte[], ISocketWrapper> onClientReceive = this.OnClientReceives;
                do
                {
                    action2 = onClientReceive;
                    Action<byte[], ISocketWrapper> action3 = (Action<byte[], ISocketWrapper>)Delegate.Combine(action2, value);
                    onClientReceive = Interlocked.CompareExchange<Action<byte[], ISocketWrapper>>(ref this.OnClientReceives, action3, action2);
                }
                while (onClientReceive != action2);
            }
            remove
            {
                Action<byte[], ISocketWrapper> action2;
                Action<byte[], ISocketWrapper> onClientReceive = this.OnClientReceives;
                do
                {
                    action2 = onClientReceive;
                    Action<byte[], ISocketWrapper> action3 = (Action<byte[], ISocketWrapper>)Delegate.Remove(action2, value);
                    onClientReceive = Interlocked.CompareExchange<Action<byte[], ISocketWrapper>>(ref this.OnClientReceives, action3, action2);
                }
                while (onClientReceive != action2);
            }
        }

        public AsyncSocket(ushort port)
        {
            if (!this.enabled)
            {
                this.port = port;
                this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port));
                this.Connection.Listen(100);
                this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
                this.enabled = true;
            }
        }

        private void AsyncConnect(IAsyncResult res)
        {
            AsyncSocketWrapper wrapper = null;
            try
            {
                string iPAddress = "";
                wrapper = new AsyncSocketWrapper();
                wrapper.Create(this.Connection.EndAccept(res));
                iPAddress = wrapper.Socket.RemoteEndPoint.ToString().Split(new char[] { ':' })[0].ToString();
                if (!BruteforceProtection.IsBanned(iPAddress))
                {
                    BruteforceProtection.AddWatch(iPAddress);
                    if (wrapper.Socket == null)
                    {
                        this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
                    }
                    else
                    {
                        if (this.OnClientConnects != null)
                        {
                            this.OnClientConnects(wrapper);
                        }
                        wrapper.Socket.BeginReceive(wrapper.Buffer, 0, wrapper.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), wrapper);
                        this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
                    }
                }
            }
            catch (SocketException exception)
            {
                Program.SaveException(exception);
                C02.Console.WriteLine(exception);
                if (this.enabled)
                {
                    this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
                }
            }
            catch (ObjectDisposedException exception2)
            {
                Program.SaveException(exception2);
                C02.Console.WriteLine(exception2);
            }
        }

        private void AsyncReceive(IAsyncResult res)
        {
            AsyncSocketWrapper asyncState;
            bool flag = false;
            try
            {
                SocketError error;
                asyncState = (AsyncSocketWrapper)res.AsyncState;
                int num = asyncState.Socket.EndReceive(res, out error);
                if ((error == SocketError.Success) && (num > 0))
                {
                    flag = true;
                    byte[] buffer = new byte[num];
                    for (int i = 0; i < num; i++)
                    {
                        buffer[i] = asyncState.Buffer[i];
                    }
                    if (this.OnClientReceives != null)
                    {
                        this.OnClientReceives(buffer, asyncState);
                    }
                    asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState);
                }
                else
                {
                    this.InvokeDisconnect(asyncState);
                }
            }
            catch (SocketException exception)
            {
                Program.SaveException(exception);
                C02.Console.WriteLine(exception);
            }
            catch (ObjectDisposedException exception2)
            {
                Program.SaveException(exception2);
                C02.Console.WriteLine(exception2);
            }
            catch (Exception exception3)
            {
                Program.SaveException(exception3);
                if (flag)
                {
                    asyncState = (AsyncSocketWrapper)res.AsyncState;
                    asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState);
                }
            }
        }

        public void Disable()
        {
            if (this.enabled)
            {
                this.Connection.Disable();
                this.enabled = false;
            }
        }

        public void Enable()
        {
            if (!this.enabled)
            {
                this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port));
                this.Connection.Listen(this.backlog);
                this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
                this.enabled = true;
            }
        }

        private void enabledCheck(string Variable)
        {
            if (this.enabled)
            {
                throw new Exception("Cannot modify " + Variable + " while socket is enabled.");
            }
        }

        public void InvokeDisconnect(AsyncSocketWrapper Client)
        {
            if (Client != null)
            {
                try
                {
                    if (Client.Socket.Connected)
                    {
                        Client.Socket.Shutdown(SocketShutdown.Both);
                        Client.Socket.Close();
                        if (this.OnClientDisconnects != null)
                        {
                            this.OnClientDisconnects(Client);
                        }
                        Client.Connector = null;
                        Client = null;
                    }
                    else
                    {
                        if (this.OnClientDisconnects != null)
                        {
                            this.OnClientDisconnects(Client);
                        }
                        Client.Connector = null;
                        Client = null;
                    }
                }
                catch (ObjectDisposedException exception)
                {
                    Program.SaveException(exception);
                    C02.Console.WriteLine(exception);
                }
            }
        }

        public int Backlog
        {
            get
            {
                return this.backlog;
            }
            set
            {
                this.enabledCheck("Backlog");
                this.backlog = value;
            }
        }

        public int ClientBufferSize
        {
            get
            {
                return this.clientbuffersize;
            }
            set
            {
                this.enabledCheck("ClientBufferSize");
                this.clientbuffersize = value;
            }
        }

        public bool Enabled
        {
            get
            {
                return this.enabled;
            }
        }

        public ushort Port
        {
            get
            {
                return this.port;
            }
            set
            {
                this.enabledCheck("Port");
                this.port = value;
            }
        }
    }
}
11/14/2013 16:40 turk55#13
Have you put any effort in trying to fix it ?
If yes, what did you try to do?

You can't expect people to help solve your problems if you haven't put any effort in yourself.
11/14/2013 21:37 hadeset#14
An access violation exception occurs, when unmanaged memory allocated by P/Invoke functions, does not get released, and eventually gets accessed by managed part of the code. Unmanaged resources are for example MySQL connections, file handles etc.. Basically not using .Net regular functions means, that you are taking a risk of getting those kinds of exceptions.

So, I think you should see if all such unmanaged resources get released(disposed) correctly and memory allocated by P/Invoke functions gets released, because the Garbage Collector will not collect those for you.