(MPU6050) After about 5 seconds the yaw angle starts to increase very rapidly.

Here’s my code (I’m using the MPU6050 library):

#include "I2Cdev.h"
#include "MPU6050.h"

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif

MPU6050 mpu;

int16_t ax, ay, az;
int16_t gx, gy, gz;

int16_t calax, calay, calaz;
int16_t calgx, calgy, calgz;

float angleX, angleY, angleZ;

int endTime;

void setup(){
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    Wire.begin();
  #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
    Fastwire::setup(400, true);
  #endif
  
  Serial.begin(9600);
  mpu.initialize();
  
  Serial.println("Testing connection");
  Serial.println(mpu.testConnection() ? "connection successful" : "connection failed");
  Serial.println("Please don't move device, calibrating...");
  
  for(int i=0;i<50;i++){
    mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    calax+=ax;
    calay+=ay;
    calaz+=az;
    calgx+=gx;
    calgy+=gy;
    calgz+=gz;  
    delay(25);
  }
  //find average
  calax/=25;
  calay/=25;
  calaz/=25;
  calgx/=25;
  calgy/=25;
  calgz/=25;
  
  Serial.println("Done!");

}

void loop(){
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); //read accl and gyro values 
  angleX += ((gx-calgx)/131.0)*((millis()-endTime)/1000.0);
  angleY += ((gy-calgy)/131.0)*((millis()-endTime)/1000.0);
  angleZ += ((gz-calgz)/131.0)*((millis()-endTime)/1000.0);
  endTime = millis();
  Serial.println(angleZ);
  delay(5);
}

In the loop, I get the raw degrees per second and multiply that by how many second have passed and continually add it to the angle variable. When watching it through the Serial Monitor, there is normal drifting and it gets to about -.5 degrees and all of a sudden jumps to like -300 degrees and increases very quickly. Any advice?